-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCpuBurner.java
More file actions
31 lines (25 loc) · 1.05 KB
/
CpuBurner.java
File metadata and controls
31 lines (25 loc) · 1.05 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
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
public class CpuBurner {
public static void main(String[] args) {
int numThreads = 2;
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
int executionTimeSec = Integer.parseInt(System.getenv().getOrDefault("EXECUTION_TIME_SEC", "60"));
System.out.println("Starting CPU intensive tasks on " + numThreads + " threads for " + executionTimeSec + " seconds...");
for (int i = 0; i < numThreads; i++) {
executor.submit(() -> {
while (!Thread.currentThread().isInterrupted()) {
double value = Math.pow(Math.random(), Math.random());
}
});
}
try {
Thread.sleep(executionTimeSec * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
executor.shutdownNow();
System.out.println("CPU intensive tasks stopped.");
}
}