Question About Bukkit Scheduler

Discussion in 'Spigot Plugin Development' started by john01dav, May 23, 2015.

  1. Hello Spigot! If I have an asynchronous task, say every 10 ticks, what will happen if a single instance of the task takes more than 10 ticks? This is a network task, so this is very possible and will undoubtedly be a common scenario.
     
  2. There are two variations of this:

    - sync: if the task hangs, so will your Minecraft server and the next run of your task will be delayed, along with every tick on your server. World time, mob movement and more will be affected.
    - async: the task get's run on its own independent thread. It will take as long as it takes, and nothing else will wait on it.
     
    • Agree Agree x 5
  3. If that happens, the threads could pile up and eventually cause issues of you never stop and give it a chance to catch up.
     
  4. I misphrased the OP so the answers here don't answer my question, here's a clarification: If I have a asynchronous task, will it be started again before it finishes it's previous iteration?
     
  5. Yes.
     
  6. Ok, will it cause delays in other tasks if I force the task to wait (ie. by making the run method synchronized)?
     
  7. async task: force task to wait -> by making run method sync?
    do you even concurrency?

    the whole point of running things async is to not lock the main thread. therefore if you need to wait on (pseudo here) say a Futurable<T> then you can
     
  8. Simple answer, no, it shouldn't. Of course, you probably shouldn't do this, as the tasks would pile up (for that particular Runnable), which could cause memory leaks and performance issues in the long run.

    My question to you is: why would you want to do this? Surely there's a better way to accomplish what you're trying to do?
     
  9. You should run the task asynchronously without letting bukkit handle the repeat. Handle the repeat yourself when your previous thread is completed by sending itself to the scheduler again.
     
    • Agree Agree x 1
  10. I'll just have it return out of the task method if there is another task running, which will be kept track of in a boolean which happens before, synchronized access, etc.