-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDemoApp.java
More file actions
60 lines (43 loc) · 1.08 KB
/
DemoApp.java
File metadata and controls
60 lines (43 loc) · 1.08 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import com.stackimpact.agent.StackImpact;
import java.util.Random;
public class DemoApp {
private static Object lock = new Object();
public static void main(String args[]) throws Exception {
StackImpact.start(System.getenv("AGENT_KEY"), "ExampleJavaApp");
while (true) {
long startTS = System.currentTimeMillis();
simulateCPULoad(20);
Thread t = new Thread(new Runnable() {
public void run() {
try {
synchronized(lock) {
Thread.sleep(80);
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
});
t.start();
simulateLockWait();
t.join();
long timeout = 1000 - (System.currentTimeMillis() - startTS) - 10;
if (timeout > 0) {
Thread.sleep(timeout);
}
}
}
public static void simulateCPULoad(int usage) throws Exception {
Random rand = new Random();
for (int i = 0; i < usage * 1000000; i++) {
rand.nextInt(100000);
}
}
public static void simulateLockWait() throws Exception {
Thread.sleep(10);
synchronized(lock) {
Thread.sleep(10);
}
}
}