This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

when input stream times out  RSS feed

 
sarveswaran meenakshi sundaram
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I have a client which reads data from a server. I have set SOTimeOUt for the client socket as x seconds so that the thread will come out of read if it waits for x seconds. The following code illustrates the condition:

{ ........
..........
clientSocket.setSoTimeout(30000);
..........
...........

clientSocket.dataInputStream.read(buffer,startIndex,length);

.........
..........
}

Suppose that the thread waits on read for 29999 ms since there is no data available on inputStream till that then. At the 30000 th milli second, data is availbale in inputStream and read() will actually start writing in to buffer. Now, will read be interrputed because of SOTimeOut or the thread will not be interrupted? If so why?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is kind of irrelivant because computers don't really have the kind of millisecond granularity that you are requiring and since Java is multithreaded, a thread may be elegable for execution for some time (i.e. after a timeout expires) before it is actually executed. Suffice to say, if there is data available before the timeout expires, the data will be read in full. If the data is not available before the timeout, an exception will be thrown.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!