Async Tasks...

Discussion in 'Plugin Development' started by Michael Rhodes, Nov 5, 2012.

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

    Michael Rhodes

    Hello,

    I have a question about scheduling repeating tasks and server performance.

    Is it better to make a new repeating task for everything I want to repeat, or make one repeating task with a shorter delay, and keep timers for the things I need to do.

    I know this may not be explained right, so I'll use an example.

    Monster Spawning. I want to control this and have my code run every 20 seconds.
    Hunger Degen. Every 1min I want to run code for this. Difference players will decrease at different rates.

    I assume that there is some "magic" number of AsyncTasks that is too much.... so, should I just make a new repeatign task for everything, or just make a few.. or is one big catch all ok ?

    Thanks, and I hope this is somewhat clear..

    Michael
     
  2. Offline

    SirTyler

    My biggest use for tasks has always been Delays, maybe you can use my example to solve your question or just give you ideas.

    So what I usually do is create a Delay Manager and in that manager it contains a List of the Delayable interface. That interface has only one defined method, "update", and the manager has a method called "update". I then schedule a repeating task to call the update method on the manager, which then loops through the list of delaybles and calls update on them. Simply put, every time the task ticks (usually I set it every second or so) the manager updates all the delays, which in turn take their proper action. Now I could create a task for every delay, but by doing this I save the server from running multiple tasks at once, and instead have a single task that handles the delays itself.
     
  3. Offline

    md_5

    It would be better to create many async tasks. Since Bukkit is a scheduler, there is no point putting a scheduler inside a scheduler. Scheduler-ception would be bad.
     
  4. Offline

    Michael Rhodes

    I kinda like SirTyler's idea. I would think at some point there could be too many threads going and lag the server.

    I will try these ideas out and see what works best... thanks
     
Thread Status:
Not open for further replies.

Share This Page