-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinator.java
More file actions
65 lines (58 loc) · 1.41 KB
/
Copy pathCoordinator.java
File metadata and controls
65 lines (58 loc) · 1.41 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
61
62
63
64
65
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package collegetransportapplication;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author soundarya
*/
public class Coordinator implements Runnable {
private String name;
private Commute commute;
private static long time = System.currentTimeMillis();
public Coordinator (int id, Commute commute)
{
setName("Coordinator-" + id);
this.commute = commute;
new Thread(this).start();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void msg(String m)
{
System.out.println( getName() + ": " + m);
}
//sleeps a random amount of time within provided range
private void simulatedWait(int range, int minTime)
{
int sleepTime = ((int)(Math.random()*range + minTime));
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
msg("Died :(");
}
}
@Override
public void run()
{
while(commute.getnumStudents() > 0)
{
if(commute.getWaitingCoordStudents() > 0)
{
msg("Picking up a student");
simulatedWait(1000, 500);
commute.pickUpStudents();
}
simulatedWait(1000, 500);
}
msg("No more students. Finished job.");
}
}