Separate thread pauses main thread

Discussion in 'Plugin Development' started by Fifteen, Jan 16, 2011.

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

    Fifteen

    Argh, I miss hMod. This worked perfectly in hMod. Anyway, I'm trying to test my auto-save plugin, but for some reason, when the "waiter thread" (the plugin works by waiting a while, then saving in a loop) begins sleeping, the main thread starts sleeping too, pausing the entire server in the process :| How do I fix this?

    Source: https://github.com/Fifteen/SaveMe/
     
  2. Offline

    Raphfrk

    You don't actually start a new thread, I think?

    You are statically calling StartWaiting() from the main thread.

    If you want another thread, you need to add a run() method to the Waiter class.

    Something like:

    For enabling:
    Code:
    Waiter waiter = new Waiter();
    waiter.start();
    }
    
    For disabling
    Code:
        waiter.interrupt();
    
    and in the Waiter class
    Code:
    public void run() {
        while(!isInterrrupted()) {
            save();
        }
    }
    
    That will have the Thread call save over and over again until interrupted.
     
  3. Offline

    Fifteen

    Well, it worked on hMod...

    and I want to call Save() every x milliseconds, not all the time until I call interrupt()...
     
  4. Offline

    Raphfrk

    Yeah, but your save method is

    Code:
    public static void Save() throws InterruptedException {
         server.e.a(true, (IProgressUpdate)null);
         StartWaiting();
    }
    
    StartWaiting() freezes the current thread.

    Also, it may be a bad idea to call console commands from another thread.

    On the hmod thing, it is possible that you were freezing the console or something.
     
Thread Status:
Not open for further replies.

Share This Page