Skip to content

Commit cd9f84f

Browse files
author
Rajeev Kumar Singh
committedMar 28, 2018
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

+1
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

+6-7
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)
Please sign in to comment.