An open ObjectOutputStream sends a certain object initially, and the complementing ObjectInputStream successfully deserializes it. This OIS is then passed to the constructor of a separate thread class, which is required to continue read()ing further (updated) objects seamlessly. This part isn't happening. Is there something eluding me about the requirements when 'context switching' that stream going on here? Many thanks.
Asked
Active
Viewed 145 times
1 Answers
1
The most important thing to do is to flush()
the ObjectOutputStream before creating the ObjectInputStream, if you don't do this you can get into a deadlock.
Passing the ObjectInputStream to another thread won't cause a problem, in fact it avoids this issue if you read from different thread than you write to.

Peter Lawrey
- 525,659
- 79
- 751
- 1,130
-
The output stream is buffered, and the input stream blocks waiting for the header even if you don't write anything yourself. – Peter Lawrey Aug 15 '12 at 14:12
-
I believe you only have to *construct* the OOS first, before the OIS. – user207421 Aug 15 '12 at 23:54