Why is timeunit Java util. Members of concurrent?

Java's timeunit enumeration is useful for many different tasks related to time, not just concurrency; And other time related classes like date are Java Part of util So why is timeunit Java util. Members of concurrent?

Solution

In addition to providing methods to use time with different granularity, timeunit also provides thread aware methods such as timedjoin:

Public void timedjoin (thread, long timeout) throws interruptedexception

I think this class originated from helping common parallel programming tasks, such as deferred execution Because it has two different functions (managing time granularity; applying time concepts to thread problems), this violates the single responsibility principle

Considering the practicability and popularity of timeunit external concurrent code, a more perfect solution may be a Java util. Timeunit enumeration, used to manage time granularity, and a separate Java util. The concurrent class is used for applications in threads

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>