Running a task on a new thread

Discussion in 'Plugin Development' started by ohtwo, Mar 6, 2013.

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

    ohtwo

    Hey guys, so basically this is my understanding of running a task on a new thread:

    Running a task on another thread means that it will not slow the operations on the main thread. I would like to update a database onDisable(), and I believe I should be running this update task on a new, separate thread. My question is, if the onDisable() tasks finish first, will the update database task shut down too? Or will it finish before the whole server stops?

    What are some other applications that should be run on separate threads?
     
  2. Offline

    RealDope

    Why not just run it on the main thread? If you want the whole thing to wait for your new thread to finish, you might as well just use the main one.

    Besides, onDisable() isn't going to affect players, it will just make a slightly slower shutdown, which nobody is really that concerned with lol
     
  3. Offline

    Lecrayen

    if your idea is to save stuff on plugin stop/reload, you should just run the task on disable - the server stops on disable anyways.
     
  4. Offline

    ohtwo

    That makes sense, but I'm still curious about whether the operation will finish or not. Just for future reference so that I know when to run tasks on separate threads or not.
     
  5. Offline

    Lecrayen

    The disable event waits for everything inside it to finish as long as it's part of itself. I am not sure if sending it off to a different thread will allow it to finish before the server is completely shutdown so I'd just advise running whatever saving method you use completely inside the onDisable() or as a method within the main class, not in a separate thread. Like I said before - The server is already "paused" when the plugins and stuff are being disabled. You'll notice that when you type /reload on a server with a few plugins.
     
    ohtwo likes this.
  6. Offline

    ohtwo

    Also, what does the runTaskLaterAsynchronously() do? I'm very new to organizing tasks on threads, so please bear with me.
     
  7. Offline

    Lecrayen

    I'm completely new to threads themselves :) just using my general knowledge of processing/computing/and coding to help you out. If you look at http://wiki.bukkit.org/Plugin_Tutorial there is a link to scheduler programming. It tells you what you can and can't do with the scheduler to prevent your server from killing itself.
     
  8. Offline

    ohtwo

Thread Status:
Not open for further replies.

Share This Page