-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemover.java
60 lines (50 loc) · 1.01 KB
/
Remover.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
public class Remover implements Runnable{
int[] array;
public Remover(int[] array)
{
this.array = array;
}
public void run()
{
int pointer = 0;
int counter = 0;
while(true)
{
for(int i : array)
{
if(i == 0)
counter++;
}
if(counter >= 5)
{
System.out.println("Waiting for new number generation...");
synchronized(array)
{
try {
array.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
counter = 0;
}
synchronized(array)
{
System.out.println("Number " + array[pointer] + " from index " + pointer + " has been removed!");
array[pointer] = 0;
array.notifyAll();
}
pointer++;
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(pointer > 4)
pointer = 0;
counter = 0;
}
}
}