Lock lock = new ReentrantLock();
lock.lock();
// 此处为何返回true,不应该被锁了吗?
System.out.println(lock.tryLock()); // =>true
lock.unlock();
System.out.println(lock.tryLock()); // => true
Lock lock = new ReentrantLock();
lock.lock();
// 此处为何返回true,不应该被锁了吗?
System.out.println(lock.tryLock()); // =>true
lock.unlock();
System.out.println(lock.tryLock()); // => true
4 回答1.5k 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
1 回答2.6k 阅读✓ 已解决
2 回答749 阅读✓ 已解决
2 回答1.8k 阅读
2 回答1.7k 阅读
2 回答1.3k 阅读
ReentrantLock.tryLock()
ReentrantLock.tryLock()
在当前线程已经持有锁的时候,返回true
。