Background timer / Thread

Discussion in 'Plugin Development' started by Unica, Jul 7, 2015.

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

    Unica

    G'day,

    I'm developing some kind of enhanced KitPvP which has certain powerups that
    I want to spawn every x interval.

    I know about BukkitRunnables and schedulars and whatnot, but I am wondering
    what the safest and least-laggiest way is to have a timer in the background.

    I do not need to display the time or have to update data every few seconds, I just want it
    running so I can respawn powerups every x minute.

    If anyone could point me into the right direction, that would be appreciated.

    yf, unica.
     
  2. @Unica
    It usually depends on the task for what's best. In your case I think running it synchronously should be fine. I myself am working on a game which has to do a lot of work every tick, so it runs on 4 different threads :p.
     
  3. @Unica for executing stuff permanently with a constant delay between the executes schedular are the way to go.Thread would be for asynchron stuff blah blah blah. nothing that matches your case. and if you say that you got a delay of minutes there is no need to handle a own thread. just go with bukkit schedulars.

    how much work is it to spawn such a powerup?
     
  4. Offline

    Unica

    @Shmobi

    It's like spawning an entity (ex. armor stand / itemframe or w/e).
    If I were to start a runnable object on server load, would I be fine? As in, would it not use all memory?

    I understand a certain memory is required, but I just want the most efficient way.
     
  5. @Unica no matter if threading or scheduling, those all are just "subprocesses" of the real process. threading/scheduling only takes as much space as they need atm. so this question should be less about memory/resources and more about performance. spawning stuff is quickly done and will be executed in the background by other threads anyways as far as i know. so its totally fine to use a bukkitrunnable. maybe even the best way. starting a thread at the begin of your plugin would force you to handle and save a thread and remove it when the plugin gets disabled. this can cause errors (especially asynchron threads, because when you spawn an entity while some other thread is looping though the list of entities, it can cause errors. stuff like that). Also i think bukkit is using some sort of array to store their schedulars, so there is already a certain amount of memory selected for them. not all they need but some, so i think you would be cheeper and faster by using bukkitschedulars
     
Thread Status:
Not open for further replies.

Share This Page