Async Viod

Discussion in 'Plugin Development' started by P_S, Jan 16, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    P_S

    Hi,
    how can i run void asynchronously ??
    Code:
        private String getText(String preURL) {
            try {
                URL url = new URL(preURL);
                URLConnection connection = url.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String text = in.readLine();
             
                return text;
         
            } catch (Exception e) {
                e.printStackTrace();
             
                return "" + e;
             
            }
        }
    This function run by player command async ...
    Thx for responses
     
  2. Offline

    Comphenix

    Take a look at scheduling programming.

    And remember, never interact with parts of the Bukkit API inside the asynchronous method (or thread) UNLESS you know they're thread safe. This is admittedly a very small subset of the API (sendMessage(), getOnlinePlayers()) though, so you will often have to schedule a synchronous task inside the asynchronous method instead.
     
Thread Status:
Not open for further replies.

Share This Page