Skip to content

Commit 8514df2

Browse files
committed
Added an example of ExecutorService
1 parent 1bc3eed commit 8514df2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.java8.concurrency.examples;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
import java.util.concurrent.TimeUnit;
6+
7+
public class ExecutorServiceDemo {
8+
9+
public static void main(String[] args) {
10+
11+
try {
12+
ExecutorService service = Executors.newSingleThreadExecutor();
13+
service.submit(() -> {
14+
String name = Thread.currentThread().getName();
15+
System.out.println("Hello - " + name);
16+
});
17+
service.shutdown();
18+
service.awaitTermination(5, TimeUnit.SECONDS);
19+
} catch (InterruptedException e) {
20+
e.printStackTrace();
21+
}
22+
}
23+
24+
}

0 commit comments

Comments
 (0)