Java's TimeUnit
enum is useful for many different tasks related to time, not just concurrency; and other time-related classes like Date
are part of java.util
. So why is TimeUnit
a member of java.util.concurrent
?
java.util.concurrent.TimeUnit. A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units.
Concurrency Utilities for Java EE is an asynchronous programming model that enables you to submit or schedule tasks to run in parallel, create threads that inherit Java EE context, and transfer Java EE context to invocation of interfaces such as asynchronous callbacks.
It is probably there for historical reasons:
TimeUnit
is widely used in the concurrency utilitiesInterestingly, the new date API in Java 8 has a ChronoUnit
enum which is similar to the TimeUnit
enum, but applied to dates and times. In particular, a ChronoUnit
can be converted to a Duration
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With