Java: New Thread.sleep Alternative

(No Ratings Yet)
 Loading ...

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.

Related Posts with Thumbnails

One Response to “Java: New Thread.sleep Alternative”

  1. 1
    Neal Says:

    Thread.sleep I have read has no guarantees..Does this have? Don’t think so

Leave a Reply

Spam protection by WP Captcha-Free