线程中的Tomcat死锁

时间:2013-09-04 13:57:22

标签: java tomcat servlets tomcat7 deadlock

我正在使用Tomcat 7.0.42作为使用websockets的应用程序。如果我的应用程序负载很重,我的一些使用websockets的线程会出现死锁。

是否有针对此问题的解决方法,因为我找不到修复方法?

我使用Atmpshere 2.0RC3运行时原生。

这是我的线程转储的相关部分。我用Samurai来检测死锁的线程。

     "Atmosphere-Shared-AsyncOp-267"   daemon prio=10 tid=0x00007efed8118000 nid=0x2eb5 waiting for monitor entry [0x00007efe798ca000]      java.lang.Thread.State: BLOCKED (on object monitor)      at org.apache.catalina.websocket.WsOutbound.writeTextMessage(WsOutbound.java:165)      - waiting to lock <0x00000005ef4c6988> (a org.apache.catalina.websocket.WsOutbound)      
at org.atmosphere.container.version.TomcatWebSocket.write(TomcatWebSocket.java:49)      
at org.atmosphere.websocket.WebSocket.write(WebSocket.java:199)      
at org.atmosphere.websocket.WebSocket.write(WebSocket.java:168)   
   at org.atmosphere.websocket.WebSocket.write(WebSocket.java:40)     
 at org.atmosphere.cpr.AtmosphereResponse$2.write(AtmosphereResponse.java:574)      
at org.atmosphere.handler.AbstractReflectorAtmosphereHandler.onStateChange(AbstractReflectorAtmosphereHandler.java:169)      
at org.atmosphere.cpr.DefaultBroadcaster.invokeOnStateChange(DefaultBroadcaster.java:1027)   
   at org.atmosphere.cpr.DefaultBroadcaster.prepareInvokeOnStateChange(DefaultBroadcaster.java:1047)    
  at org.atmosphere.cpr.DefaultBroadcaster.executeAsyncWrite(DefaultBroadcaster.java:921)     
 at org.atmosphere.cpr.DefaultBroadcaster$3.run(DefaultBroadcaster.java:580)      - locked <
    0x00000005ef4b77f8> (a org.atmosphere.cpr.AtmosphereResourceImpl)     
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)  
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)   
   at java.util.concurrent.FutureTask.run(FutureTask.java:166)    
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)    
  at java.lang.Thread.run(Thread.java:724)  


    "Atmosphere-Scheduler-2"   daemon prio=10 tid=0x00007efee9c77800 nid=0x257d waiting for monitor entry [0x00007efe831ef000]      java.lang.Thread.State: BLOCKED (on object monitor)      
at org.atmosphere.cpr.AsynchronousProcessor.completeLifecycle(AsynchronousProcessor.java:476)      - waiting to lock <0x00000005ef4b77f8> (a org.atmosphere.cpr.AtmosphereResourceImpl)     
 at org.atmosphere.cpr.AsynchronousProcessor.timedout(AsynchronousProcessor.java:437)      
at org.atmosphere.cpr.AsynchronousProcessor$AsynchronousProcessorHook.timedOut(AsynchronousProcessor.java:633)     
 at org.atmosphere.websocket.DefaultWebSocketProcessor.close(DefaultWebSocketProcessor.java:483)      
at org.atmosphere.container.TomcatWebSocketHandler.onClose(TomcatWebSocketHandler.java:80)      
at org.apache.catalina.websocket.StreamInbound.doOnClose(StreamInbound.java:222)      
at org.apache.catalina.websocket.WsOutbound.doWriteBytes(WsOutbound.java:423)      
at org.apache.catalina.websocket.WsOutbound.doWriteText(WsOutbound.java:442)      
at org.apache.catalina.websocket.WsOutbound.writeTextMessage(WsOutbound.java:174)      - locked <
    0x00000005ef4c6988> (a org.apache.catalina.websocket.WsOutbound)      
at org.atmosphere.container.version.TomcatWebSocket.write(TomcatWebSocket.java:49)      
at org.atmosphere.websocket.WebSocket.write(WebSocket.java:199)      
at org.atmosphere.websocket.WebSocket.write(WebSocket.java:168)      
at org.atmosphere.websocket.WebSocket.write(WebSocket.java:40)      
at org.atmosphere.cpr.AtmosphereResponse$2.write(AtmosphereResponse.java:574)      
at org.atmosphere.cpr.AtmosphereResponse.write(AtmosphereResponse.java:992)      
at org.atmosphere.interceptor.HeartbeatInterceptor$1$1.call(HeartbeatInterceptor.java:104)      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)      
at java.util.concurrent.FutureTask.run(FutureTask.java:166)      
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)     
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)     
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
    at java.lang.Thread.run(Thread.java:724)

1 个答案:

答案 0 :(得分:0)

Tomcat bug !!! 您需要将Tomcat更新到最新版本或配置如下:

添加你的web.xml:

  <init-param>
      <param-name>org.atmosphere.cpr.Broadcaster.writeTimeout</param-name>
      <param-value>VALUE</param-value>
  </init-param>

VALUE是毫秒,我建议20000 - 30000.