Scenario :
I am making a clone of the popular card game. There must be a period during which people can join the game. Sometimes the period is too short. Therefore, I want people to extend the waiting period. For sample numbers, the default lobby time is 45 seconds, and each extension is 15 seconds.
Question :
I decided to use Java Timers. When the lobby starts, TimerTask is assigned for 45 seconds:
UnoStartTimer.schedule(new UnoStartTask(), 45000);
When someone wants to extend the delay, this is the pseudocode I want to run:
UnoStartTimer.reschedule(UnoStartTimer.getNextScheduledTime() + 15000);
A quick look at javadoc indicates that there is no such simple solution with the Timer class.
Here are the features I came up with:
- I need to use a different planning class (I think I saw something called ScheduledExecutorService in an answer to another question, but it didnβt immediately seem to be the solution to my problem)
- There is a way to do this with Timer, and I clearly don't notice it.
- There is no easy way to do this.
So which one?
source share