I’m debugging a Java application that runs several threads. After a while of watching the log it seems that one of those threads is not running anymore. My guess is that the
While it is possible have timeouts while waiting for locks on synchronized methods, implementing these is unwieldy. Basically you would spawn a timer thread which would interrupt the block thread after T seconds...not nice.
If you're using Java 5 or higher I strongly suggest you see what the new concurrency classes offer. For example, you might consider using the ReentrantLock, which has a method tryLock(long timeout, TimeUnit unit) which will allow you to attempt to acquire the lock but allows you to escape after a fixed amount of time.