-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (35 loc) · 1.11 KB
/
Main.java
File metadata and controls
40 lines (35 loc) · 1.11 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
package com.yurii.salimov.lesson06.task03;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 6.3 Создать 100 потоков, каждый их которых выведет на экран
* свой номер и дождется, пока его прервут.
*
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public class Main {
public static void main(String[] args) {
try {
final Collection<Thread> threads = createThreads();
Thread.sleep(5000);
interruptThreads(threads);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Collection<Thread> createThreads() {
final List<Thread> threads = new ArrayList<>();
Thread thread;
for (int i = 0; i < 100; i++) {
thread = new MyThread();
thread.start();
threads.add(thread);
}
return threads;
}
private static void interruptThreads(final Collection<Thread> threads) {
threads.stream().forEach(Thread::interrupt);
}
}