-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumer.java
More file actions
83 lines (72 loc) · 2.12 KB
/
Consumer.java
File metadata and controls
83 lines (72 loc) · 2.12 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.io.*;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Consumer {
protected float min = 10000;
protected BlockingQueue<Float> queue1 = new ArrayBlockingQueue<>(510);
protected BlockingQueue <Float> queue2 = new ArrayBlockingQueue<>(510);
protected BlockingQueue <Float> queue3 = new ArrayBlockingQueue<>(510);
protected Object lock = new Object();
Thread tConmin = new Thread(new Runnable() {
@Override
public void run() {
consumerMin();
}
});
public float consumerMin ()
{
while (true)
{
synchronized (lock)
{
while (queue1.size()==0)
{
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
float value = 0;
try {
value = queue1.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (value < min)
{
min = value;
}
lock.notify();
return min;
}
}
static String Readfile (String fname)
{
FileInputStream fstream = null;
try {
fstream = new FileInputStream(fname);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
String resultString = "";
try {
while ((strLine = br.readLine()) != null) {
resultString+= strLine + "\r\n";
}
}
catch (IOException e) {
e.printStackTrace();
}
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return resultString;
}
}