posted 14 years ago
No. You can set up timeouts for most blocking operations, though (Object.wait, the await method provided by many classes under java.util.concurrent, acquire* methods also from classes under java.util.concurrent, poll and offer from BlockingQueue, etc.). You could also use getThreadCpuTime from the Threading MX bean to get the time used by the thread and exit if the limit has been exceeded.
Note that there's no way to (safely) terminate a thread that's blocked indefinitely, e.g. trying to acquire a monitor (entering a synchronized block).