Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is TimeUnit a member of java.util.concurrent?

Tags:

java

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?

like image 452
cnnr Avatar asked Oct 21 '13 21:10

cnnr


People also ask

What is Java Util Concurrent TimeUnit?

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.

What is Concurrency Utilities in Java?

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.


1 Answers

It is probably there for historical reasons:

  • the legacy date API has not evolved much over the past few years
  • TimeUnit is widely used in the concurrency utilities

Interestingly, 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.

like image 155
assylias Avatar answered Oct 07 '22 17:10

assylias