Skip to content

Commit f3537ac

Browse files
authored
SemaPhoreDemo double acquire fix
tryAcquire() already acquires a permit, if one is available (no need to call acquire() after it)
1 parent e1a6b9f commit f3537ac

1 file changed

Lines changed: 0 additions & 1 deletion

File tree

  • core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore

‎core-java-modules/core-java-concurrency-basic/src/main/java/com/baeldung/concurrent/semaphore/SemaPhoreDemo.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public void execute() throws InterruptedException {
1212
System.out.println("Number of threads waiting to acquire: " + semaphore.getQueueLength());
1313

1414
if (semaphore.tryAcquire()) {
15-
semaphore.acquire();
1615
// perform some critical operations
1716
semaphore.release();
1817
}

0 commit comments

Comments
 (0)