File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronized Timeout" Watch "synchronized Timeout" New topic
Author

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) {
_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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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

[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: synchronized Timeout