我的应用每天早晨都关闭,从监视等待的线程数从50增加到200,使用此命令转储线程堆栈:
/opt/dabai/tools/jdk1.8.0_211/bin/jmap -dump:format=b,file=room-service-201911281010.dump 6546
我使用MAT检查了堆栈,并发现许多线程挂起,日志部分是这样的:
Thread Stack
qtp1785687166-3607
at sun.misc.Unsafe.park(ZJ)V (Native Method)
at java.util.concurrent.locks.LockSupport.park(Ljava/lang/Object;)V (LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt()Z (AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(I)V (AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(I)V (AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.CountDownLatch.await()V (CountDownLatch.java:231)
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet()Ljava/lang/Object; (BlockingSingleSubscriber.java:81)
at reactor.core.publisher.Mono.block()Ljava/lang/Object; (Mono.java:1494)
at org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorRegistryBeans$ReactiveHealthIndicators.lambda$adapt$1(Lorg/springframework/boot/actuate/health/ReactiveHealthIndicator;)Lorg/springframework/boot/actuate/health/Health; (HealthIndicatorRegistryBeans.java:61)
at org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorRegistryBeans$ReactiveHealthIndicators$$Lambda$553.health()Lorg/springframework/boot/actuate/health/Health; (Unknown Source)
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health()Lorg/springframework/boot/actuate/health/Health; (CompositeHealthIndicator.java:98)
at org.springframework.boot.actuate.health.HealthEndpoint.health()Lorg/springframework/boot/actuate/health/Health; (HealthEndpoint.java:50)
at org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(Lorg/springframework/boot/actuate/endpoint/SecurityContext;)Lorg/springframework/boot/actuate/endpoint/web/WebEndpointResponse; (HealthEndpointWebExtension.java:54)
at sun.reflect.GeneratedMethodAccessor352.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Method.java:498)
at org.springframework.util.ReflectionUtils.invokeMethod(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (ReflectionUtils.java:282)
at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(Lorg/springframework/boot/actuate/endpoint/InvocationContext;)Ljava/lang/Object; (ReflectiveOperationInvoker.java:76)
at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(Lorg/springframework/boot/actuate/endpoint/InvocationContext;)Ljava/lang/Object; (AbstractDiscoveredOperation.java:61)
at org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$ServletWebOperationAdapter.handle(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object; (AbstractWebMvcEndpointHandlerMapping.java:294)
at org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object; (AbstractWebMvcEndpointHandlerMapping.java:355)
at sun.reflect.GeneratedMethodAccessor283.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke([Ljava/lang/Object;)Ljava/lang/Object; (InvocableHandlerMethod.java:189)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(Lorg/springframework/web/context/request/NativeWebRequest;Lorg/springframework/web/method/support/ModelAndViewContainer;[Ljava/lang/Object;)Ljava/lang/Object; (InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(Lorg/springframework/web/context/request/ServletWebRequest;Lorg/springframework/web/method/support/ModelAndViewContainer;[Ljava/lang/Object;)V (ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lorg/springframework/web/method/HandlerMethod;)Lorg/springframework/web/servlet/ModelAndView; (RequestMappingHandlerAdapter.java:892)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lorg/springframework/web/method/HandlerMethod;)Lorg/springframework/web/servlet/ModelAndView; (RequestMappingHandlerAdapter.java:797)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Object;)Lorg/springframework/web/servlet/ModelAndView; (AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (HttpServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V (FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V (HttpServlet.java:750)
我的问题是:如何配置无功健康指标超时?如果/ health请求无响应,则返回失败或避免等待线程。
答案 0 :(得分:0)
我正在尝试实现这样的自定义反应健康指标:
@Component
public class MyReactiveHealthIndicator implements ReactiveHealthIndicator {
@Override
public Mono<Health> health() {
return checkDownstreamServiceHealth().onErrorResume(
ex -> Mono.just(new Health.Builder().down(ex).build())
);
}
private Mono<Health> checkDownstreamServiceHealth() {
// we could use WebClient to check health reactively
Health health = new Health.Builder().up().build();
return Mono.just(health).timeout(Duration.ofSeconds(5));
}
}
也许这会有所帮助。