How make an infinite while

Discussion in 'Plugin Development' started by 4z3rty, Jun 26, 2012.

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

    4z3rty

    Hi,
    I want to check something every x minutes.
    I have think to make an infinite while and to use :
    Code:
    myPlugin.getServer().getScheduler().scheduleAsyncRepeatingTask(myPlugin, new Runnable() {
     
    public void run() {
    System.out.println("This message is printed by an async thread");
    }
    }, 60L, 200L);
    
    Escuse me for my spelling, I'm french !
     
  2. Offline

    Everdras

    Why are you using an async thread? That's usually not safe.

    Use a sync thread, and use the Scheduler run it every X minutes (but put the time period in server ticks. 20 ticks = 1 second). Have the Runnable's run() method do the check and store or process the results.

    You won't need a while loop.
     
  3. Offline

    4z3rty

    Ok, It works :
    Code:
       
    private MyPluygin plugin;
    public MyPluyginListener(MyPluygin plugin){
            this.plugin = plugin;
            
            plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
                
                public void run() {
                System.out.println("This message is printed by an async thread");
                }
                }, 60L, 200L);
        }
     
  4. Offline

    Everdras

    Okay, but do you know what you're doing?

    You're working with truly concurrent code here- async threads. You'll need to be sure to use locks and synchronization, and avoid all non-thread-safe Bukkit API calls.
     
    ferrybig likes this.
Thread Status:
Not open for further replies.

Share This Page