Solved Best way to track time, efficently

Discussion in 'Plugin Development' started by Colby l, Feb 15, 2014.

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

    Colby l

    I need about 24 timers for what I was thinking of doing, and I believe I could do it more efficiently.

    So, here's what I need to do:

    I have 12 different sets of permissions, for 12 different configured systems.

    Each configured system needs to have two checks done (for a fly payment system), one check to see if the player is in an allowed fly zone, and another timer to withdraw the cost to fly.

    I cannot combine the two, because the withdraw time needs to be longer than the fly check time. Also, I was thinking about having each player have a timer, but then realized iterating through a hash map 12 different times was better than making 2 timers for each person, times 100 people on a server.

    Lastly, will having 24 timers on a server be hugely inefficient? 12 of the 24 timers will be running nearly once per second, and the other 12 will be running between every 2 - 30 seconds.

    Thanks for the help!
     
  2. Offline

    TeeePeee

    I generally run two threads, a synchronous and an asynchronous, that tick every second (if I need to do something like you are). This way, you can easily use the modulo operator (%) to call each separate event.

    For example,
    if(ticks%60==0) { ... }
    if(ticks%90==0) { ... }

    Of course you would just need to track and integer named tick in your runnable.
     
  3. Offline

    Colby l

    I've never tried it that way, but I'll definitely try that, thanks!
     
Thread Status:
Not open for further replies.

Share This Page