Skip to content

Commit c8415aa

Browse files
author
Rajeev Kumar Singh
committed
Await termination
1 parent a390a28 commit c8415aa

File tree

9 files changed

+54
-0
lines changed

9 files changed

+54
-0
lines changed

java-callables-and-futures/Readme.md

Whitespace-only changes.

java-callables-and-futures/src/InvokeAllExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
3232
// The result is printed only after all the futures are complete. (i.e. after 5 seconds)
3333
System.out.println(future.get());
3434
}
35+
36+
executorService.shutdown();
3537
}
3638
}

java-callables-and-futures/src/InvokeAnyExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
2828
String result = executorService.invokeAny(Arrays.asList(task1, task2, task3));
2929

3030
System.out.println(result);
31+
32+
executorService.shutdown();
3133
}
3234
}

java-executors-and-thread-pool/Readme.md

Whitespace-only changes.

java-lock-objects-and-atomic-variables/Readme.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Created by rajeevkumarsingh on 11/05/17.
3+
*/
4+
public class ReadWriteLockExample {
5+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.concurrent.ExecutorService;
2+
import java.util.concurrent.Executors;
3+
import java.util.concurrent.locks.ReentrantLock;
4+
5+
/**
6+
* Created by rajeevkumarsingh on 11/05/17.
7+
*/
8+
9+
public class ReentrantLockCounter {
10+
private final ReentrantLock lock = new ReentrantLock();
11+
12+
private int count = 0;
13+
14+
public void increment() {
15+
lock.lock();
16+
try {
17+
count = count + 1;
18+
} finally {
19+
lock.unlock();
20+
}
21+
}
22+
23+
public int getCount() {
24+
return count;
25+
}
26+
27+
public static void main(String[] args) {
28+
ExecutorService executorService = Executors.newFixedThreadPool(2);
29+
30+
ReentrantLockCounter counter = new ReentrantLockCounter();
31+
32+
for(int i = 0; i < 1000; i++) {
33+
executorService.submit(() -> counter.increment());
34+
}
35+
36+
executorService.shutdown();
37+
38+
System.out.println("Final count is : " + counter.getCount());
39+
}
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Created by rajeevkumarsingh on 11/05/17.
3+
*/
4+
public class StampedLockExample {
5+
}

java-threads-and-runnables/Readme.md

Whitespace-only changes.

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