:
while (dis.available()>0){
, . , .
, PipedInputStream/PipedOutputStream , . , checkStateForReceive, , , :
} else if (readSide != null && !readSide.isAlive()) {
throw new IOException("Read end dead");
}
(readSide - .)
, :
java.io.IOException: Read end dead
at java.io.PipedInputStream.checkStateForReceive(PipedInputStream.java:246)
at java.io.PipedInputStream.receive(PipedInputStream.java:210)
at java.io.PipedOutputStream.write(PipedOutputStream.java:132)
at java.io.DataOutputStream.writeLong(DataOutputStream.java:207)
at java.io.DataOutputStream.writeDouble(DataOutputStream.java:242)
write receieve , checkStateForReceieve, , .
, :
while(!isDone.get()) {
, , :
if (avg>1E5)
isDone.set(true);
100 101, 1e5. , , runningTotal > 1E5.
:
- , .
- IOException , . , : , . , , .
:
, join .
try(
PipedOutputStream pos= new PipedOutputStream();
PipedInputStream pis =new PipedInputStream(pos)
){
AtomicBoolean isDone = new AtomicBoolean(false);
NumGen ng = new NumGen(pos,isDone);
RunningAvg ra = new RunningAvg(pis,isDone);
ng.start();
ra.start();
try {
ng.join();
ra.join();
} catch(InterruptedException ie) {}
} catch (IOException e) {
e.printStackTrace();
}