In a Java thread dump, you can see locks mentioned within stack traces.
There seems to be three kinds of information:
1:
- locked <0x00002aab329f7fa0> (a java.io.BufferedInputStream)
2:
- waiting to lock <0x00002aaaf4ff6fa0> (a org.alfresco.repo.lock.LockServiceImpl)
3:
- parking to wait for <0x00002aaafbf70bb8> (a java.util.concurrent.SynchronousQueue$TransferStack)
- 1: The thread has obtained a lock on object 0x00002aab329f7fa0.
- 2&3: Seem to say that the thread is waiting for the lock on said object to become available...
but what is the difference 2 and 3?
You will get "waiting to lock" in the thread dump when using intrinsic locks and "parking to wait for" when using locks from java.util.concurrent. Consider the following example:
With
lockTest.intrinsicLock()
you will get the following thread dump:while
lockTest.reentrantLock()
produce:In my opinion, the java.util.concurrent package almost use LockSupport.park() method to block thread, such as CountDownLatch, ReentrantLock which belong to abstractqueuedsynchronized framework. Thus, the 3rd scenario in your questions means your code finally calls LockSupport.park() method, for you use the concurrent class in java.util.concurrent package, the 2nd scenario means you use synchronized keywork and call wait() method explicitly.