Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronized Timeout

 
Maalti Iyer
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
How long will java waits before it times out on an object lock?. In otherwords, I've a socket connection to an external server
(code snippet :
synchronized(_obj) {
if (!_primaryInUse &&_outputStream1 != null) {
_outputStream1.write(_pollingMessage.getBytes());
_outputStream1.flush();
index = _inputStream1.read(pollResp, 0, 27);
}
)
In a multi-threaded environment, there can only be one connection a client can establish with this external server (threads shouls share this connection).
Thanks for your time
maalti Iyer.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"synchronized" never times out.
[ August 11, 2003: Message edited by: Ernest Friedman-Hill ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to insert some sort of timeout here, you can try having another thread close() the outputStream if it detects no activity after a certain period of time. This is often unreliable though - the close() may simply block too. You should probably look into the NIO classes for nonblocking IO.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic