Rather than using Java’s static Thread.sleep method and calculating how many seconds you need to pass to its parameter, a simple class called TimeUnit simplifies its usage according to hours, minutes and seconds. You can use it using either of the following …
|
1 2 3 |
TimeUnit.HOURS.sleep(1); TimeUnit.MINUTES.sleep(10); TimeUnit.SECONDS.sleep(30); |
The sample above will run every hour, every 10 minutes and every 30 seconds. Pretty simple and much less tedious right?