Nicer sleep() With TimeUnit


import java.util.concurrent.TimeUnit;
//...
      try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException ex) {}

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 8, Java 9: Bootstrap, Effective, Architectures, Single Page Apps, Progressive Web Apps, HTML 5, ES 6, CSS 3 and Microservices

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

sleep as a method of TimeUnit, is this OOP? I would rather like to have Thread.sleep(Duration)

Posted by asd on December 17, 2015 at 11:29 PM CET #

I once saw in a JavaOne session that there is a sleep method in some JDK class that does not throw an InterruptedException. Do you know which class it is?

Posted by Juan on October 21, 2016 at 01:17 AM CEST #

What about sleep in JEE environments?
As already stated in http://www.adam-bien.com/roller/abien/entry/can_i_start_threads_in one must not manage Threads, and sleep is a managing action, even if you use it through TimeUnit (which effectively calls Thread.sleep).

I've seen proposals to use Timers, but that's a big overhead if you just want to have a very small delay between retries with unstable resources.

Posted by Daniel on February 09, 2017 at 09:26 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License