Jac*_*ine 1 java concurrency deadlock
我有一个使用Jersey构建的REST服务.
当我对我的REST API执行"curl"时,该命令挂起.
我运行jstack&这是两个处于BLOCKED状态的线程的汇总输出.
"pool-2-thread-11" prio=6 tid=0x01d51800 nid=0x2394
waiting for monitor entry [0x05e6f000..0x05e6fce8]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.moi.DefaultImageProcessor$DownloadAndScaleCallable.call(
DefaultImageProcessor.java:168)
- waiting to lock <0x257aa440>
(com.moi.ImageUriMutexImpl$MutexImpl)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
ThreadPoolExecutor.java:885)
"pool-2-thread-10" prio=6 tid=0x01d51000 nid=0x18d0
waiting for monitor entry [0x05e1f000..0x05e1fd68]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.moi.DefaultImageProcessor$DownloadAndScaleCallable.call(
DefaultImageProcessor.java:168)
- waiting to lock <0x257aa6b8>
(com.moi.ImageUriMutexImpl$MutexImpl)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
ThreadPoolExecutor.java:885)
Run Code Online (Sandbox Code Playgroud)
我想知道如何读取此堆栈转储.我应该在僵局中寻找什么迹象?
更新我解决了我的问题!基本上我在synchronized块中做了一个HttpClient 4.0 GET.HttpClient表现不佳而且没有返回并且它保持在锁上.通过jstack,有几个线程持有锁,导致上面的问题.我现在明白,这不是死锁,但我的同步块需要很长时间才能返回.
从小堆栈跟踪中,线程只等待获取锁定.在跟踪中查找对象0x257aa440和0x257aa6b8,看看谁锁定了这些对象.检查该线程是否被阻止.
在死锁情况下,您会看到阻塞状态的完整循环.同时多次跟踪以确认阻塞状态是暂时的还是漫长的等待.