Skip to content

Commit cd9f84f

Browse files
author
Rajeev Kumar Singh
committed
cleanup
1 parent 6946aca commit cd9f84f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

java-lock-objects-and-atomic-variables/src/AtomicIntegerExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public int getCount() {
1818
return count.get();
1919
}
2020
}
21+
2122
public class AtomicIntegerExample {
2223
public static void main(String[] args) throws InterruptedException {
2324
ExecutorService executorService = Executors.newFixedThreadPool(2);

java-lock-objects-and-atomic-variables/src/ReentrantLockMethodsExample.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import java.util.concurrent.TimeUnit;
44
import java.util.concurrent.locks.ReentrantLock;
55

6-
class ReentrantLockCounterIncrement {
6+
class ReentrantLockMethodsCounter {
77
private final ReentrantLock lock = new ReentrantLock();
88

99
private int count = 0;
1010

1111
public int incrementAndGet() {
12-
// Check if lock is currently acquired by any thread
12+
// Check if the lock is currently acquired by any thread
1313
System.out.println("IsLocked : " + lock.isLocked());
1414

15-
// Check if lock is acquired by the current thread itself.
15+
// Check if the lock is acquired by the current thread itself.
1616
System.out.println("IsHeldByCurrentThread : " + lock.isHeldByCurrentThread());
1717

1818
// Try to acquire the lock
@@ -43,19 +43,18 @@ public class ReentrantLockMethodsExample {
4343
public static void main(String[] args) {
4444
ExecutorService executorService = Executors.newFixedThreadPool(2);
4545

46-
ReentrantLockCounterIncrement lockCounterIncrement = new ReentrantLockCounterIncrement();
46+
ReentrantLockMethodsCounter lockMethodsCounter = new ReentrantLockMethodsCounter();
4747

4848
executorService.submit(() -> {
4949
System.out.println("IncrementCount (First Thread) : " +
50-
lockCounterIncrement.incrementAndGet() + "\n");
50+
lockMethodsCounter.incrementAndGet() + "\n");
5151
});
5252

5353
executorService.submit(() -> {
5454
System.out.println("IncrementCount (Second Thread) : " +
55-
lockCounterIncrement.incrementAndGet() + "\n");
55+
lockMethodsCounter.incrementAndGet() + "\n");
5656
});
5757

5858
executorService.shutdown();
59-
6059
}
6160
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy