What purpose does the TimeUnit class have?

John Zukowski

The TimeUnit class allows you to work with time quanities as both an amount and a unit of measurement. For instance, instead of always working with milliseconds when you want to put a thread to sleep, via Thread.sleep(3000), you can say TimeUnit.SECONDS.sleep(3) and you'll sleep for 3 seconds with both. Other methods require you to pass in both the instance of TimeUnit (one of NANOSECONDS, MICROSECONDS, MILLISECONDS, or SECONDS), and the quantity of that unit. See the tryLock() method of the Lock interface for one such usage.