Proper way of implementing "timers" in Java?

java, timer

Solution

You should use the `ScheduledThreadPoolExecutor` class, which does exactly that.

Problem

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?

Original source

Related problems