-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExecutorsExample.java
More file actions
29 lines (23 loc) · 1.16 KB
/
ExecutorsExample.java
File metadata and controls
29 lines (23 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ExecutorsExample {
public static void main(String[] args) {
System.out.println("Inside : " + Thread.currentThread().getName());
System.out.println("Creating Executor Service...");
ExecutorService executorService = Executors.newSingleThreadExecutor();
System.out.println("Creating a Runnable...");
Runnable runnable1 = () -> {
//System.out.println("Inside : " + Thread.currentThread().getName());
Thread.currentThread().setName("threadM");
System.out.println("Inside : " + Thread.currentThread().getName());
};
Runnable runnable2 = () -> {
System.out.println("Inside : " + Thread.currentThread().getName());
Thread.currentThread().setName("threadN");
System.out.println("Inside : " + Thread.currentThread().getName());
};
System.out.println("Submit the task specified by the runnable to the executor service.");
executorService.submit(runnable1);
executorService.submit(runnable2);
}
}