forked from wesleyegberto/java-new-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStressPlatformThread.java
More file actions
23 lines (22 loc) · 756 Bytes
/
StressPlatformThread.java
File metadata and controls
23 lines (22 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.concurrent.Executors;
import java.util.stream.IntStream;
/**
* Run: `java --enable-preview --source 19 <FileName.java>`
*/
public class StressPlatformThread {
public static void main(String[] args) {
var executor = Executors.newCachedThreadPool();
// WARNING: 10K threads sleeping 500 may restart your computer (save everything before run it!)
// IntStream.range(0, 10_000).forEach(i -> {
IntStream.range(0, 1_000).forEach(i -> {
executor.submit(() -> {
System.out.printf("Thread %d - %s%n", i, Thread.currentThread().getName());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.printf("Thread %d - %s interrupted%n", i, Thread.currentThread().getName());
}
});
});
}
}