![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e97. Determining If the Current Thread Is Holding a Synchronized LockA thread can determine if it is holding the synchronized lock of a particular object.public synchronized void myMethod() { boolean hasLock = false; Object o = new Object(); // Determine if current thread has lock for o hasLock = Thread.holdsLock(o); // false synchronized (o) { hasLock = Thread.holdsLock(o); // true } // Check if current thread has lock for current object hasLock = Thread.holdsLock(this); // true }
e93. Stopping a Thread e94. Determining When a Thread Has Finished e95. Pausing the Current Thread e96. Pausing a Thread e98. Allowing an Application with Live Threads to Exit e99. Listing All Running Threads e100. Using a Thread-Local Variable e101. Getting the Stack Trace of an Exception e102. Implementing a Work Queue
© 2002 Addison-Wesley. |