dcsimg
Can pipe streams stay for a long time?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gang_Zhao
Posted On:   Thursday, June 7, 2001 09:48 PM

I have written the following source code: import java.io.*; class OrderMonitor { private PipedInputStream is = null; private ObjectInputStream ois = null; public OrderMonitor(PipedInputStream is) { this.is = is; } public void run () { DeliverResp dr; while (true) { try { ois = new ObjectInputStream(is); dr = (DeliverResp)ois.readObject(); ois.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } } } Everytime I run this program,the first round can run correctly and when the second round begins,the    More>>

I have written the following source code:
import java.io.*;

class OrderMonitor
{
private PipedInputStream is = null;
private ObjectInputStream ois = null;

public OrderMonitor(PipedInputStream is)
{
this.is = is;
}

public void run ()
{
DeliverResp dr;
while (true)
{
try
{
ois = new ObjectInputStream(is);
dr = (DeliverResp)ois.readObject();
ois.close();
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
}

Everytime I run this program,the first round can run correctly and when the second round begins,the following exception is thrown out:
orderMonitor: DeliverResp.result = 0
orderMonitor: parse sMsgContent = Y1 0001 13910526168
orderMonitor: before orderDeliverRespQueue.pull
java.io.IOException: Pipe closed
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable. (Throwable.java:94)
at java.lang.Exception. (Compiled Code)
at java.io.IOException. (Compiled Code)
at java.io.PipedInputStream.read(Compiled Code)
at java.io.ObjectInputStream.read(Compiled Code)
at java.io.DataInputStream.readShort(DataInputStream.java:268)
at java.io.ObjectInputStream.readShort(ObjectInputStream.java:1556)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:724
)
at java.io.ObjectInputStream. (ObjectInputStream.java:165)
at OrderMonitor.run(Compiled Code)

What's the matter with ObjectInputStream.close()?
Does it close the underlying InputStream when I invoke its close?
Can I repeatly use the same pipe streams?

   <<Less
About | Sitemap | Contact