Java Creating a new ObjectInputStream Blocks

When you construct an ObjectInputStream, in the constructor the class attempts to read a header that the associated ObjectOutputStream on the other end of the connection has written. It will not return until that header has been read. So if you are seeing the constructor ‘hang’, it’s because the other side of the socket either hasn’t used an ObjectOutputStream, or hasn’t flushed the data yet.

Leave a Comment