forked from MaXal/PerformanceInvestigation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadCountTest.java
More file actions
30 lines (27 loc) · 986 Bytes
/
ThreadCountTest.java
File metadata and controls
30 lines (27 loc) · 986 Bytes
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
package com.koltsa.utilities;
public class ThreadCountTest {
private static int threadCount = 0;
/**
* Checks how many threads current JVM supports by sequentially spawning the threads and ...
* ... printing out their number into standard output.
*/
public static void checkHowManyThreadsJvmCouldHave() {
Object monitor = new Object();
for (;;) {
new Thread(() -> {
synchronized (monitor) {
ThreadCountTest.threadCount++;
System.out.printf("Thread count: %d%n", ThreadCountTest.threadCount++);
}
for (;;) {
// hold thread in active state
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
}