Java: New Thread.sleep Alternative
|
|
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?
Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.








February 7th, 2010 at 9:03 am
Thread.sleep I have read has no guarantees..Does this have? Don’t think so