The Advantage of using Lock is that tryLock() is there to try to get the Lock if available, also with defined time to try to acquire lock before giving up
as;
private final Lock queueLock = new ReentrantLock();
queueLock.lock();
try {
queueLock.tryLock(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.out.println(" Unable to acquire Lock");
e.printStackTrace();
}
as;
private final Lock queueLock = new ReentrantLock();
queueLock.lock();
try {
queueLock.tryLock(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
System.out.println(" Unable to acquire Lock");
e.printStackTrace();
}
No comments:
Post a Comment