I need to do some periodic checks in Java code. Some things get executed in separate threads, and there I need to check things every 5 seconds, then some other things every 10 minutes, etc.
How should I implement these “timers” in Java? Should I just loop and then send threads to sleep for some time?
What would be the proper way of doing it?
You should use the
ScheduledThreadPoolExecutorclass, which does exactly that.