-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChocolateBoiler.java
71 lines (61 loc) · 1.4 KB
/
ChocolateBoiler.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
67
68
69
70
public class ChocolateBoiler {
private boolean empty;
private boolean boiled;
private static ChocolateBoiler instance;
private ChocolateBoiler() {
empty = true;
boiled = false;
}
public void fill(){
if(isEmpty()){
empty = false;
boiled = false;
}
}
public void drain(){
if(isEmpty() && isBoiled()){
//drain the boiled milk and chocolate
empty = true;
}
}
public void boil(){
if(!isEmpty() && isBoiled()){
//bring the contents to a boil
boiled = true;
}
}
public static ChocolateBoiler getInstance(){
if (instance==null){
instance=new ChocolateBoiler();
System.out.print("Primera Instancia creada");
}
else{
System.out.print("Instancia ya existe");
}
return instance;
}
public boolean isEmpty(){
return empty;
}
public boolean isBoiled(){
return boiled;
}
}
class MyThread implements Runnable {
Thread t;
MyThread (String thread){
name = threadname;
t = new Thread(this, "thread");
t.start();
}
}
public void run(){
ChocolateBoiler.getInstance();
}
public class Multithread{
public static void main(){
for (int i=0; i<10; i++){
new MyThread();
}
}
}