标签:
情况:
在高并发情况下,查看线程栈信息,有大量的线程BLOCKED。
从线程栈得知,线程栈中出现了阻塞,锁在了com.fasterxml.jackson.databind.ser.SerializerCache.untypedValueSerializer(SerializerCache.java:74)上。
1 "catalina-exec-1453" #1525 daemon prio=5 os_prio=0 tid=0x00007f1010098800 nid=0x2675 waiting for monitor entry [0x00007f0fd74dc000] 2 java.lang.Thread.State: BLOCKED (on object monitor) 3 at com.fasterxml.jackson.databind.ser.SerializerCache.untypedValueSerializer(SerializerCache.java:74) 4 - waiting to lock <0x000000072ac28ed8> (a com.fasterxml.jackson.databind.ser.SerializerCache) 5 at com.fasterxml.jackson.databind.SerializerProvider._findExplicitUntypedSerializer(SerializerProvider.java:1087) 6 at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.hasSerializerFor(DefaultSerializerProvider.java:392) 7 at com.fasterxml.jackson.databind.ObjectMapper.canSerialize(ObjectMapper.java:2412) 8 at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canWrite(AbstractJackson2HttpMessageConverter.java:165) 9 at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:157) 10 at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:101) 11 at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:199) 12 at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71) 13 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:128) 14 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) 15 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) 16 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) 17 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 18 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 19 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 20 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 21 at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 22 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 23 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 24 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 25 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 26 at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) 27 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 28 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 29 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 30 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 31 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 32 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 33 at com.qianye.zhaimi.master.filter.ExceptionFilter.doFilter(ExceptionFilter.java:53) 34 at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) 35 at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) 36 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 37 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 38 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 39 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 40 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 41 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 42 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 43 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 44 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 45 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 46 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 47 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 48 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 49 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 50 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 51 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) 52 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1760) 53 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1719) 54 - locked <0x0000000733f4d960> (a org.apache.tomcat.util.net.NioChannel) 55 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 56 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 57 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 58 at java.lang.Thread.run(Thread.java:745)
分析:
深入分析源代码,从代码中查看得知序列化方法中采用了synchronized关键字,导致BLOCKED。
1 /** 2 * Method that checks if the shared (and hence, synchronized) lookup Map might have 3 * untyped serializer for given type. 4 */ 5 public JsonSerializer<Object> untypedValueSerializer(Class<?> type) 6 { 7 synchronized (this) { 8 return _sharedMap.get(new TypeKey(type, false)); 9 } 10 }
标签:
原文地址:http://www.cnblogs.com/snifferhu/p/5071413.html