-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessManagement.java
40 lines (34 loc) · 1.01 KB
/
ProcessManagement.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
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
public class ProcessManagement {
Timer timer;
ProgNormalNode owner;
private Random random;
public ProcessManagement(int seconds, ProgNormalNode owner) {
this.random = new Random();
this.owner = owner;
timer = new Timer();
timer.schedule(new ForExit(), seconds * 1000, seconds * 1000);
}
class ForExit extends TimerTask {
int action;
public void run() {
if(owner.isInitialized()) {
action = random.nextInt(2);
if (action == 0) {
owner.tryFork();
} else if (owner.getUsedSlots() > 0) {
// owner.doExit();
}
} else {
println("Node not initialized, won't mess with processes");
}
}
}
private void println(String str) {
this.owner.println(str);
}
// public static void main(String args[]) {
// }
}