Name

TimeUnit

Synopsis

The constants defined by this enumerated type represent granularities of time. Timeout and delay specifications throughout the java.util.concurrent package are specified by a long value and TimeUnit constant that specifies the interpretation of that value.

TimeUnit defines conversion methods that convert values expressed in one unit to values in another unit. More interestingly, it defines convenient alternatives to Thread.sleep( ), Thread.join( ), and Object.wait( ).

java.util.concurrent.TimeUnit

Figure 16-96. java.util.concurrent.TimeUnit

public enum TimeUnit {
// Enumerated Constants
                  NANOSECONDS,  
     MICROSECONDS,  
     MILLISECONDS,  
     SECONDS;  
// Public Class Methods
     public static TimeUnit valueOf(String name);  
     public static final TimeUnit[ ] values( );  
// Public Instance Methods
     public long convert(long duration, TimeUnit unit);  
     public void sleep(long timeout) throws InterruptedException;  
     public void timedJoin(Thread thread, long timeout) throws InterruptedException;  
     public void timedWait(Object obj, long timeout) throws InterruptedException;  
     public long toMicros(long duration);  
     public long toMillis(long duration);  
     public long toNanos(long duration);  
     public long toSeconds(long duration);  
}

Passed To

Too many methods to list.

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.