File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes synchronized Timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronized Timeout" Watch "synchronized Timeout" New topic

synchronized Timeout

Maalti Iyer
Ranch Hand

Joined: Jul 11, 2001
Posts: 52
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) {
index =, 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

Joined: Jul 08, 2003
Posts: 24199

"synchronized" never times out.
[ August 11, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
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.

"I'm not back." - Bill Harding, Twister
Don't get me started about those stupid light bulbs.
subject: synchronized Timeout
jQuery in Action, 3rd edition