|
3 | 3 | import java.util.concurrent.TimeUnit; |
4 | 4 | import java.util.concurrent.locks.ReentrantLock; |
5 | 5 |
|
6 | | -class ReentrantLockCounterIncrement { |
| 6 | +class ReentrantLockMethodsCounter { |
7 | 7 | private final ReentrantLock lock = new ReentrantLock(); |
8 | 8 |
|
9 | 9 | private int count = 0; |
10 | 10 |
|
11 | 11 | public int incrementAndGet() { |
12 | | - // Check if lock is currently acquired by any thread |
| 12 | + // Check if the lock is currently acquired by any thread |
13 | 13 | System.out.println("IsLocked : " + lock.isLocked()); |
14 | 14 |
|
15 | | - // Check if lock is acquired by the current thread itself. |
| 15 | + // Check if the lock is acquired by the current thread itself. |
16 | 16 | System.out.println("IsHeldByCurrentThread : " + lock.isHeldByCurrentThread()); |
17 | 17 |
|
18 | 18 | // Try to acquire the lock |
@@ -43,19 +43,18 @@ public class ReentrantLockMethodsExample { |
43 | 43 | public static void main(String[] args) { |
44 | 44 | ExecutorService executorService = Executors.newFixedThreadPool(2); |
45 | 45 |
|
46 | | - ReentrantLockCounterIncrement lockCounterIncrement = new ReentrantLockCounterIncrement(); |
| 46 | + ReentrantLockMethodsCounter lockMethodsCounter = new ReentrantLockMethodsCounter(); |
47 | 47 |
|
48 | 48 | executorService.submit(() -> { |
49 | 49 | System.out.println("IncrementCount (First Thread) : " + |
50 | | - lockCounterIncrement.incrementAndGet() + "\n"); |
| 50 | + lockMethodsCounter.incrementAndGet() + "\n"); |
51 | 51 | }); |
52 | 52 |
|
53 | 53 | executorService.submit(() -> { |
54 | 54 | System.out.println("IncrementCount (Second Thread) : " + |
55 | | - lockCounterIncrement.incrementAndGet() + "\n"); |
| 55 | + lockMethodsCounter.incrementAndGet() + "\n"); |
56 | 56 | }); |
57 | 57 |
|
58 | 58 | executorService.shutdown(); |
59 | | - |
60 | 59 | } |
61 | 60 | } |
0 commit comments