- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumer.java
More file actions
Latest commit
83 lines (72 loc) · 2.12 KB
/
Copy pathConsumer.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
importjava.io.*;
importjava.util.Random;
importjava.util.concurrent.ArrayBlockingQueue;
importjava.util.concurrent.BlockingQueue;
publicclassConsumer {
protectedfloatmin = 10000;
protectedBlockingQueue<Float> queue1 = newArrayBlockingQueue<>(510);
protectedBlockingQueue <Float> queue2 = newArrayBlockingQueue<>(510);
protectedBlockingQueue <Float> queue3 = newArrayBlockingQueue<>(510);
protectedObjectlock = newObject();
ThreadtConmin = newThread(newRunnable() {
@Override
publicvoidrun() {
consumerMin();
}
});
publicfloatconsumerMin ()
{
while (true)
{
synchronized (lock)
{
while (queue1.size()==0)
{
try {
lock.wait();
} catch (InterruptedExceptione) {
e.printStackTrace();
}
}
}
floatvalue = 0;
try {
value = queue1.take();
} catch (InterruptedExceptione) {
e.printStackTrace();
}
if (value < min)
{
min = value;
}
lock.notify();
returnmin;
}
}
staticStringReadfile (Stringfname)
{
FileInputStreamfstream = null;
try {
fstream = newFileInputStream(fname);
} catch (FileNotFoundExceptione) {
e.printStackTrace();
}
BufferedReaderbr = newBufferedReader(newInputStreamReader(fstream));
StringstrLine;
StringresultString = "";
try {
while ((strLine = br.readLine()) != null) {
resultString+= strLine + "\r\n";
}
}
catch (IOExceptione) {
e.printStackTrace();
}
try {
br.close();
} catch (IOExceptione) {
e.printStackTrace();
}
returnresultString;
}
}