-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclicker.java
66 lines (50 loc) · 1.5 KB
/
clicker.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class HiLoPri {
public static void main(String args[]) {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
clicker hi = new clicker(Thread.NORM_PRIORITY + 2, "High");
clicker lo = new clicker(Thread.NORM_PRIORITY - 2, "Low");
hi.start();
lo.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println("Main thread interrupted.");
}
lo.stop();
// hi.stop();
// Wait for child threads to terminate.
try {
hi.t.join();
lo.t.join();
} catch (InterruptedException e) {
System.out.println("InterruptedException caught");
}
System.out.println("Low-priority thread: " + lo.click);
System.out.println("High-priority thread: " + hi.click);
}
}
class clicker implements Runnable {
long click = 0;
String type = null;
private volatile boolean running = true;
Thread t;
public clicker(int p, String s) {
t = new Thread(this);
type = s;
// System.out.println("Type :: "+s);
t.setPriority(p);
}
public void run() {
// System.out.println("Type Run :: "+type);
while (running) {
click++;
}
}
public void stop() {
running = false;
}
public void start() {
t.start();
}
}
//~ Formatted by Jindent --- http://www.jindent.com