Repository navigation
Expand file tree
/
Copy pathSolution.java
More file actions
80 lines (49 loc) · 2.23 KB
/
Copy pathSolution.java
File metadata and controls
80 lines (49 loc) · 2.23 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//And there came unto me one of the seven angels which had the seven vials full of the seven last plagues, and talked with me, saying, Come hither, I will shew thee the bride, the Lamb's wife. (Revelation 21:9)
package com.javarush.task.task28.task2812;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/*
ShutdownNow!
*/
public class Solution {
public static void main(String[] args) throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 1; i <= 10; i++) {
final int localId = i;
executor.submit(new Runnable() {
public void run() {
doExpensiveOperation(localId);
}
});
}
List<Runnable> list = executor.shutdownNow();
for (Runnable r: list
) {
System.out.println(r);
}
}
private static void doExpensiveOperation(int localId) {
System.out.println(Thread.currentThread().getName() + ", localId="+localId);
}
}
/*
ShutdownNow!
Разберись в чем отличие методов shutdown и shutdownNow. Выведи список всех незавершенных задач на экран.
Должно получиться что-то вроде:
pool-1-thread-1, localId=1
pool-1-thread-2, localId=2
pool-1-thread-3, localId=3
pool-1-thread-4, localId=4
pool-1-thread-5, localId=5
java.util.concurrent.FutureTask@7e6cbb7a was not completed
java.util.concurrent.FutureTask@7c3df479 was not completed
java.util.concurrent.FutureTask@7106e68e was not completed
java.util.concurrent.FutureTask@7eda2dbb was not completed
java.util.concurrent.FutureTask@6576fe71 was not completed
Требования:
1. В методе main класса Solution должен быть вызван метод shutdownNow на объекте executor.
2. В методе main класса Solution на экран должны быть выведены все задачи которые не успел выполнить executor.
3. Метод main должен быть публичным.
4. Метод main должен быть статическим.
*/