-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.java
More file actions
65 lines (56 loc) · 1.37 KB
/
Copy pathProcess.java
File metadata and controls
65 lines (56 loc) · 1.37 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
/**
* Lab 9: Thread Barrier.
* Process tries to join the barrier.
*
*/
public class Process implements Runnable {
/**
* The barrier which the process joins.
*/
private Barrier barrier;
/**
* The process name: 'Thread n', where n is the number of the thread.
*/
private String name;
/**
* The sleep time: representing the work done before joining the barrier.
*/
private int sleepTime;
/**
* The queue number of process. Ensures processes are released in FIFO order (Doesnt use java data structure)
*/
int numQueue;
/**
* Create a process.
*
* @param b the barrier.
* @param n the thread number.
* @param s the length of time to sleep before joining the barrier.
*/
public Process(Barrier b, int n, int s) {
barrier = b;
name = "Thread " + n;
sleepTime = s;
}
/**
* Get name of process.
*
* @return
*/
public String getName() {
return name;
}
/**
* A process sleeps for a while and then joins the barrier.
*
*/
@Override
public void run() {
try {
Thread.sleep(sleepTime);
barrier.joinBarrier(this);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}