Start new thread? or run asynchronous task?

Discussion in 'Spigot Plugin Development' started by Bolt, Jun 28, 2015.

  1. I'm wondering what's the best method to run perform operations outside of the main server thread. I know that I can do this with threads and also with asynchronous tasks but I'd like to know which of these two is better recommended?
     
  2. Creeoer

    Supporter

    Never access the bukkit api with asynchronous tasks, unless you want to sacrifice some thread safety.
     
  3. Run an asynchronous task if you can. It's more efficient as the threads are picked from a pool. Plus Bukkit keeps track of your tasks so it's safer.
     
    • Agree Agree x 2
  4. If I should use an asynchronous task, why is it deprecated?
     
  5. Asynchronous task.

    Check the docs, it's probably the wrong method you are using.
     
  6. I'm using the Bukkit.getScheduler().scheduleAsyncDelayedTask() should I be using another method?
     
  7. joehot200

    Supporter

    You should, but i'm currently on my phone, so i'll get back to you later on the actual code.
     
  8. Use runTaskLaterAsynchronously. Alternatively use a BukkitRunnable. They are a lot easier to handle when it comes to cancelling tasks at least.