• Post Reply Bookmark Topic Watch Topic
  • New Topic

Waking up a blocked socket read thread  RSS feed

 
Victor Ho
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When a socket read thread is blocked on InputStream-read(), what are the all the possbile ways to unblock such thread? (Note: I am using blocking sockets stil, nothing from NIO)

From my testings:
1) InputStream - close() // this works
2) Socket - close() // this works
3) Socket - shutdownInput() // does not work
4) Thread - interrupt() // does not work

Anybody know of other ways or think differently on the behavior above?

Thanks
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setSoTimeout(int timeout):

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.


--
:alex |.::the_mindstorm::.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!