• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hanging ObjectInputStream  RSS feed

 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,
I have a question about the order of Input and Output. If you change the order of the commented lines the below code doesn't work. Why?

(This code lined up better on textpad than it does here)
Obviously this is the client code. The serve code looks similar but doesn't seem to be affected by the order of output = new ObjectOutputStream or input = new ObjectInputStream. What is even more confusing is that if you change these to DataInputStream and DataOutputStream, the order makes no difference on either the client or the server. There are a few other things you have to change but it all comes down to the order of ObjectInput and ObjectOutput Streams. Is this a bug? Will it only happen on Windows NT? Does anyone have any ideas?
Dazed and confused!
J
[This message has been edited by Jay Brass (edited February 06, 2001).]

[This message has been edited by Peter Tran (edited February 06, 2001).]
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at your code (BTW, I went edited it to make it easier to read), the ordering should not be relevant. Have you smaller test programs with just the Object streams to see if the ordering makes a difference? I think it's something else. I would try writing a small test programming using only the Object stream.
-Peter
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Peter,
For cleaning up the code and for keeping me sane. I didn't believe the order should make a difference either. But that was all I could think of. When you swap those two lines around, the thing just hangs. I will throw some code at it to see just where the problem is (client or server). BTW this was the small version. And taking your advice, maybe some test programs with ObjectStreams might be in order.
Thx again,
J
 
Jay Dellinger
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted to chime in on this as well. I experienced the exact same problem. I isolated my communication class and tested this out. If you create the ObjectInputStream first, it hangs. If you create the ObjecOutputStream first, it works fine. Very strange. But thanks for figuring that out. That's the last thing I would have tried.
This was true on Win2k. Here's my java version.
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I have not tried on other platforms or versions to see if this behavior is widespread.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I see the original posts here are rather old, but what the heck. This problem is explained in the API for the ObjectInputStream constructor:
Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.

If the constructor blocks, waiting for something that won't happen until the next line, program execution cannot continue.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!