I/O Deadlock.

K

Ken Adams

Basically I have a client/server system and I implement the following ocde
to set up the streams on both the client and the server.
I seem to have deadlock when program execution enters this area. How to I
stop the deadlock between the client and server?
Thanks


Socket socket = new Socket(hostName, port);
ObjectInputStrem inStream = new ObjectInputStream(new
BufferedInputStream(socket.getInputStream()));

ObjectOutputStream outStream = new ObjectOutputStream(new
BufferedOutputStream(socket.getOutputStream()));
 
D

David Zimmerman

Ken said:
Basically I have a client/server system and I implement the following ocde
to set up the streams on both the client and the server.
I seem to have deadlock when program execution enters this area. How to I
stop the deadlock between the client and server?
Thanks


Socket socket = new Socket(hostName, port);
ObjectInputStrem inStream = new ObjectInputStream(new
BufferedInputStream(socket.getInputStream()));

ObjectOutputStream outStream = new ObjectOutputStream(new
BufferedOutputStream(socket.getOutputStream()));
The ObjectOutputStream constructor writes a header onto the given
stream. The ObjectInputStream constructor reads the header. If there is
nothing to read, the constructor will wait fot it. So, be careful what
order you create the various Object stream objects on each side.
 
T

Thomas G. Marshall

Ken Adams coughed up:
Basically I have a client/server system and I implement the following
ocde to set up the streams on both the client and the server.
I seem to have deadlock when program execution enters this area. How
to I stop the deadlock between the client and server?
Thanks


Socket socket = new Socket(hostName, port);
ObjectInputStrem inStream = new ObjectInputStream(new
BufferedInputStream(socket.getInputStream()));

ObjectOutputStream outStream = new ObjectOutputStream(new
BufferedOutputStream(socket.getOutputStream()));


Consider using the *java.nio* facility. It was designed to be less
"conforming" to OO principals, but far faster and clearer. You avoid these
massively compound decorator patterns of java.io...



--
Iamamanofconstantsorrow,I'veseentroubleallmydays.Ibidfarewelltoold
Kentucky,TheplacewhereIwasbornandraised.ForsixlongyearsI'vebeenin
trouble,NopleasureshereonearthIfound.ForinthisworldI'mboundtoramble,
Ihavenofriendstohelpmenow....MaybeyourfriendsthinkI'mjustastrangerMyface,
you'llneverseenomore.ButthereisonepromisethatisgivenI'llmeetyouonGod's
goldenshore.
 
E

Esmond Pitt

Thomas said:
Consider using the *java.nio* facility. It was designed to be less
"conforming" to OO principals, but far faster and clearer. You avoid these
massively compound decorator patterns of java.io...

.... unless the OP still wants to use serialization which is only
implemented for java.io.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top