aspose file tools
The moose likes Threads and Synchronization and the fly likes How can Socket.getInputStream() block Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How can Socket.getInputStream() block " Watch "How can Socket.getInputStream() block " New topic
Author

How can Socket.getInputStream() block

Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70
Hi All,

I am trying to find an answer to the following weird condition.


I have written Dispatcher class that accepts client requests and forwards them to appropriate server instances. There are 3 server instances.

The code is some what as follows



However the program just hangs while trying to do s.getInputStream() above. The server is running and exeuctes fine.

Why does the program block at

[ April 22, 2005: Message edited by: Naveen Sampra ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8263


The ObjectInputStream constructor blocks until it completes reading the serialization stream header. Code which waits for an ObjectInputStream to be constructed before creating the corresponding ObjectOutputStream for that stream will deadlock, since the ObjectInputStream constructor will block until a header is written to the stream, and the header will not be written to the stream until the ObjectOutputStream constructor executes. This problem can be resolved by creating the ObjectOutputStream before the ObjectInputStream, or otherwise removing the timing dependency between completion of ObjectInputStream construction and the creation of the ObjectOutputStream.

Java Object Serialization Specification


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70
Thanks for your input. I'm really perplexed with this problem.

In my code above as suggested in the quote, ObjectOutputStream is created "before" the ObjectInputStream. So why does ObjectInputStream still block ?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How can Socket.getInputStream() block
 
Similar Threads
How to transfer a bufferedImage Object?
ObjectInputStream problems "connection reset"
socket reset ?
little chat program
inputStream freezes