-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDekker.java
37 lines (30 loc) · 824 Bytes
/
Dekker.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
import java.io.*;
import java.util.Date;
public class Dekker {
int favoredThread = 1;
boolean produtorWantsToEnter = false;
boolean consumidorWantsToEnter = false;
boolean done = false;
public static void main(String args[]) throws Exception {
// Sistema
Dekker d = new Dekker();
Produtor p = new Produtor(d);
Consumidor c = new Consumidor(d);
new Thread(p).start();
new Thread(c).start();
Date d1 = new Date();
Date d2;
long dif = 0;
while (dif < (10*1000)) {
d2 = new Date();
dif = d2.getTime() - d1.getTime();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
System.err.println("ERRO: " + e.getMessage());
}
}
d.done = true;
System.out.println("O programa acabou");
}
}