Scheduler Usage Question

Discussion in 'Plugin Development' started by JeroenV, Feb 13, 2013.

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

    JeroenV

    Hello,

    I've been working with schedulers quite alot lately. However I want to reduce any kind of lag caused by my plugin.
    The question is pretty simple, which one of these 2 methods would be best to use:

    1. Create a new scheduler for every new building that has been created, and remove the scheduler when a building is removed.

    2. Create one global scheduler that has has a pretty low cooldown (if I can call it that) where every new building is stored in a hashmap with a number. This number gets incremented every time the scheduler hits, once this number hits the amount specified by the building type it will execute the desired code.


    I'm doing a complete rewrite of the plugin and I really want to get it perfect this time. If you need more information about the context feel free to ask :)

    Greets,
    Jeroen V.

    anyone?

    Still hoping for an answer.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. JeroenV
    It would help if you gave us a little more information about what code will be executed in the scheduler. From what I can ascertain it sounds like you are performing block change operations, if so I recommend using a synchronous threads as block methods are not thread safe.

    As for your question I would say using a scheduler for each building would be more efficient, this way it doesn't need to be running if nothing is happening.
     
  3. Offline

    JeroenV

    The code that gets executed can vary from removing mobs in a certain chunk to adding items in a chest to well.. pretty much anything. My worry was that there will probably be hundreds of buildings eventually which will probably cause alot of lag. I wasn't certain if creating a new scheduler object every time would cause too much lag.
     
  4. JeroenV
    No, creating a new scheduler task will not create much lag. It all depends on what you do inside the scheduler which can cause lag if you are performing CPU intensive operations.

    My advice would be this. If you anticipate that the scheduler code will need to be executed frequently I would run a central thread as you suggested initially and then run your tasks as required. However if the scheduler is only going to be called sporadically it would probably be better to call the scheduler each time you perform an operation/ set of operations.
     
Thread Status:
Not open for further replies.

Share This Page