Code example for TimeUnit

Methods: toNanos

0
    public void lockInterruptibly() throws InterruptedException { 
        sync.acquireInterruptibly(1);
    } 
 
    public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
        return sync.tryAcquireNanos(1, unit.toNanos(timeout));
    } 
 
}