I have a server where more than one client connects. Each connection spawns a new Thread, which then acts independently.
I am now facing the task of making a Lobby, where multiple WaitingRooms can be created. After 2 minutes a WaitingRoom will start the game for the players registered in a List.
Here is the problem: how can I have a timed thread? I was thinking of these solutions:
- Creating a SingleThreadExecutor and make the WaitingRooms implement Callable, so that after 2mins I can call a get on them.
- Creating a Thread associated to the WaitingRoom, doing so with a Wrapper class, which has a Runnable that every second decreases by one a variable "timer" until zero is reached.
- Creating a class that has a List that has a Thread running through them, invoking a method to decrease a variable "timer".
I shall apply this clock-thing also to PlayerTurns and to Connections.
I don't want to reinvent the clock and I am sure I'm not the first person doing something like this: is there a standard way?