[Semi-Resolved] Bukkit Scheduler/Runnables

Discussion in 'Spigot Plugin Development' started by Techtony96, May 25, 2015.

  1. Hello everyone,

    I am using the bukkit scheduler and/or runnable a lot in my code. The issue I am having is that randomly all current tasks stop and new ones are not scheduled. The only fix I have found for this is to restart the server.

    I run a almost completely custom network and therefore everything that we do is coded into one plugin. Is it possible that I am overloading the Bukkit scheduler?

    At the time of posting this, I am 159 versions behind, which I know should be updated, but I have not found ANYTHING about this issue anywhere else, and believe it is unique to my situation. I will be doing testing with a fresh version, and report my findings here.

    Here is an example how I am scheduling a custom restart command for staff: gist
    public static void shutdownServer(ServerStatus status) {
        new BukkitRunnable() {
            @Override public void run() {
        }.runTaskLater(Main.instance, 60);
    Does anyone know what may be causing the issue?
    • Like Like x 1
  2. @Techtony96 perhaps another plugin is cancelling all tasks (which includes your plugin)
  3. Have you called the method? Sometimes people forget to actually call them haha.
  4. We only use our own plugin, NCP, and Enjin on our server. It will break at seemingly random times so nothing is really canceling it. Also to mention, we have a lot of things using the scheduler; is it possible that we're overusing it?

    Yes I can guarantee it's being called and all tasks break at once.

    (Forgot to mention, I'm working on the same project as @Techtony96 )
  5. This would explain why all events stop, but why are new events not being scheduled?
    It broadcasts the message, but then doesn't shut down. Also, if the scheduler is working (Which I can tell because we have a moving scoreboard) /restart works perfectly fine.

    @XylenTV is another developer on this project and can help answer questions.
  6. Is it possible that you kill yourself with that Bukkit.shutdown() in scheduler? I bet the scheduler waits for your bukkitrunnable to finish and the bukkit.shutdown() waits for the scheduler to finish.
  7. Well, it is not only this shutdown method. And if the scheduler is working, then the restart command works perfectly. There is no one action that I can find that makes all the schedulers stop working. Sometimes it takes 5 minutes, other times it takes a few hours. (4-24)
  8. We updated our servers,


    But still no cigar.
  9. Bump.

    I am 99% sure bumping is not against the rules...
  10. It isn't, once per 24h period.

    As for the scheduler, task IDs are stored as integers, so I would expect it to crash once you reach Integer.MAX_VALUE tasks.. But I highly doubt you will ever reach that. It's all I can think of though
  11. Please give the exact number, it is very difficult to overload the scheduler unless you are doing something wrong. I recommend looking at all your runnable calls to the scheduler, or perform some instrumentation to debug/analyse the code.
  12. The only thing I can think of that is very demanding of the scheduler is:
    public class Updater implements Runnable {

        public void run() {
            for (UpdateType updateType : UpdateType.values()) {
                if (updateType.Elapsed()) {
                    Main.instance.getServer().getPluginManager().callEvent(new UpdateEvent(updateType));
    Which we start in onEnable in the main class with:
    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(), 0L, 1L);
    We use this as our own scheduler. Partly because we were having issues with it before, and thought transferring the load to the event handler might work better. It did for a while, but now it's back to breaking constantly. I can not ever find a pattern on what we change which makes the scheduler keep working for a few days at a time. Then, randomly (it seems), we don't change anything and the servers start breaking all of a sudden.
  13. That would make sense for existing tasks, but wouldn't calling the new BukkitRunnable create a new scheduler, and then that would be the only task running on the server?
  14. Hmm. This is true.. Issue goes deeper than I thought.
  15. If possible, why not extend Java's thread class, and just synchronize when you need to interact with the Bukkit API?
  16. Why would one do this?
    • Agree Agree x 1
  17. Try using the Java Timer and TimerTask for async tasks. It will reduce the BukkitScheduler overload.
  18. The issue is that 95% of what we do is with the bukkit thread, except mysql calls, so I don't think that will lighten the load on the scheduler.