Solved Quick question: Amount of BukkitRunnables

Discussion in 'Plugin Development' started by woutwoot, Jul 5, 2014.

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

    woutwoot

    Hello,

    I'm currently working on a plugin that will allow server mines to have their blocks regen after a certain amount of time. I've used runnables to achieve this. Now, while making it, I was wondering:
    • How much runnables can you have at one time? Will they use up a lot of RAM?
    • Is it a problem to schedule a (non-repeating) runnable (alomost) every BockBreakEvent?
    • Is there a better way to do this?
    Thank you, and until next time :)
     
  2. woutwoot
    • It's not really based on how many you have, it's what they do that matters. For an extreme example, you could have many runnables that simply add two numbers together, but not so many that attempt to download large files (which admittedly should be done async but that's a different matter). Also, as is the case with the people who build a 'gaming computer' and ensure they have many exabytes of RAM (that's a thing, right?) and don't pay attention to the other parts, RAM is often an unnecessary worry.
    • Again, it would depend on what you're doing. Maybe it would, maybe it wouldn't. No way of knowing this without knowing what you're doing, and how often blocks would really be broken.
    • Not really, but I'm still not entirely sure what 'this' is ^^
     
  3. Offline

    woutwoot

    Well, what I'm doing is regenerating the block to a new ore after some time. So I have this BukkitRunnable which gets called for every ore block that is broken:
    Code:java
    1. public class ResetTask extends BukkitRunnable {
    2.  
    3. private Block b;
    4. private Mine m;
    5.  
    6. ResetTask(Block b, Mine m) {
    7. this.b = b;
    8. this.m = m;
    9. }
    10.  
    11. @Override
    12. public void run() {
    13. b.setType(m.getRandomisedMaterial());
    14. }
    15. }
    16.  
     
  4. Offline

    Drkmaster83

    If the task expires and isn't a repeating task, I wouldn't see anything wrong with running tasks like that - there's no other way to do it, anyhow. Just know that if your plugin gets disabled, the ores won't auto-regenerate - all the tasks should cancel.
     
  5. Offline

    dsouzamatt

    woutwoot I think you could just cancel the block break event after whatever amount of time.
     
  6. Offline

    woutwoot

    I'm not sure. But if that would work, it would be the same ore again. My plugin randomizes that, so you can't go back to that one spot where you find diamonds every day :)
     
    dsouzamatt likes this.
  7. Offline

    fireblast709

    dsouzamatt That would have no effect. The moment you cancel it, the event has already been processed by MC
    woutwoot They generally hardly use any RAM, you could at most see a slight rise of CPU usage when using a lot of async tasks (but you are not using them - which is how it should be considering you use the Bukkit API)
     
  8. Offline

    RawCode

    why you not performed any form of heap analizis?
    why you not performed any form of benchmarking?
    why you not ever opened javadocs?

    woutwoot
     
  9. Offline

    hintss

    A better way, IMO, would be to have a list of things that store the block location and the time it was broken, then have a runnable looping through this list every x ticks and regenning the blocks that are due to be regenned.
     
    NathanWolf likes this.
  10. Offline

    woutwoot

    Good idea! Thanks.
     
Thread Status:
Not open for further replies.

Share This Page