-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStress.java
52 lines (45 loc) · 1.38 KB
/
Stress.java
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
package com.yurii.salimov.lesson12.task02;
import java.util.ArrayList;
import java.util.List;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class Stress extends Thread {
private final Parameters parameters;
public Stress(final Parameters parameters) {
this.parameters = parameters;
}
@Override
public void run() {
while (!isInterrupted()) {
final List<Thread> clients = createClients();
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
interruptedClients(clients);
System.out.println(">>> All threads is interrupted.");
return;
} catch (Exception ex) {
ex.printStackTrace();
return;
}
}
}
public Parameters getParameters() {
return this.parameters;
}
private List<Thread> createClients() {
final List<Thread> threads = new ArrayList<>();
Thread client;
for (int i = 0; i < this.parameters.getNumberOfConnections(); i++) {
client = new Client(this.parameters);
client.start();
threads.add(client);
}
return threads;
}
private static void interruptedClients(final List<Thread> clients) {
clients.forEach(Thread::interrupt);
}
}