SemaPhoreDemo double acquire fix
tryAcquire() already acquires a permit, if one is available (no need to call acquire() after it)
This commit is contained in:
parent
e1a6b9f63b
commit
f3537acf6b
@ -12,7 +12,6 @@ public class SemaPhoreDemo {
|
|||||||
System.out.println("Number of threads waiting to acquire: " + semaphore.getQueueLength());
|
System.out.println("Number of threads waiting to acquire: " + semaphore.getQueueLength());
|
||||||
|
|
||||||
if (semaphore.tryAcquire()) {
|
if (semaphore.tryAcquire()) {
|
||||||
semaphore.acquire();
|
|
||||||
// perform some critical operations
|
// perform some critical operations
|
||||||
semaphore.release();
|
semaphore.release();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user