如何解决Spring Boot 服务在空闲或服务过多请求后自动关闭
我有基于 v2.1.4.RELEASE 的“my-app”spring boot 服务。该服务充当我所有微服务的控制器。我正在使用 eureka 注册所有其他微服务以及这个 my-app(控制器)。我在此服务中遇到了一些不寻常的行为。
-
在空闲模式下它会自动停止响应。
-
当处理太多请求时,它会在一段时间后停止响应。
在深入研究日志后,我发现了以下堆栈跟踪:
01-07-2021 09:32:19.675 [AsyncResolver-bootstrap-executor-0] INFO c.n.d.s.r.aws.ConfigClusterResolver.getClusterEndpoints - Resolving eureka endpoints via configuration
01-07-2021 09:32:20.057 [Thread-13] INFO c.n.l.PollingServerListUpdater.run - Shutting down the Executor Pool for PollingServerListUpdater
01-07-2021 09:32:20.058 [Thread-9] INFO o.s.c.n.e.s.EurekaServiceRegistry.deregister - Unregistering application MY-APP with eureka with status DOWN
01-07-2021 09:32:20.058 [Thread-9] WARN c.netflix.discovery.discoveryClient.notify - Saw local status change event StatusChangeEvent [timestamp=1625112140058,current=DOWN,prevIoUs=UP]
01-07-2021 09:32:20.059 [discoveryClient-InstanceInfoReplicator-0] INFO c.netflix.discovery.discoveryClient.register - discoveryClient_MY-APP/MY-APP:9c84f59eab3882519f16fd7be15bb138: registering service...
01-07-2021 09:32:20.061 [Thread-9] INFO c.n.u.c.ShutdownEnabledTimer.cancel - Shutdown hook removed for: NFLoadBalancer-PingTimer-CALLMASTERS
01-07-2021 09:32:20.063 [discoveryClient-InstanceInfoReplicator-0] INFO c.netflix.discovery.discoveryClient.register - discoveryClient_MY-APP/MY-APP:9c84f59eab3882519f16fd7be15bb138 - registration status: 204
01-07-2021 09:32:20.073 [Thread-9] INFO c.n.u.c.ShutdownEnabledTimer.cancel - Exception caught (might be ok if at shutdown)
java.lang.IllegalStateException: Shutdown in progress
at java.lang.ApplicationShutdownHooks.remove(ApplicationShutdownHooks.java:82)
at java.lang.Runtime.removeShutdownHook(Runtime.java:239)
at com.netflix.util.concurrent.ShutdownEnabledTimer.cancel(ShutdownEnabledTimer.java:70)
at com.netflix.loadbalancer.BaseLoadBalancer.cancelPingTask(BaseLoadBalancer.java:613)
at com.netflix.loadbalancer.BaseLoadBalancer.shutdown(BaseLoadBalancer.java:864)
at com.netflix.loadbalancer.DynamicServerListLoadBalancer.shutdown(DynamicServerListLoadBalancer.java:285)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.disposableBeanAdapter.invokeCustomDestroyMethod(disposableBeanAdapter.java:337)
at org.springframework.beans.factory.support.disposableBeanAdapter.destroy(disposableBeanAdapter.java:271)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543)
at org.springframework.beans.factory.support.DefaultListablebeanfactory.destroySingleton(DefaultListablebeanfactory.java:1055)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504)
at org.springframework.beans.factory.support.DefaultListablebeanfactory.destroySingletons(DefaultListablebeanfactory.java:1062)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1026)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:975)
我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.4. 发布
com.akash
我的控制器
0.0.1-快照
我的控制器
1.8
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- new dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.12.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>MysqL</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-core</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<description>core Controller</description>
application.properties
spring.application.name=MY-APP-CONTROLLER
port.no=8585
host.name=localhost
logging.config=configuration/logback.xml
server.ip=http://my-app.eureka.com/eureka/
eureka.client.service-url.default-zone=http://my-
app.eureka.com/eureka
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=510MB
server.tomcat.max-threads=500
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
这里有什么需要做的配置吗?
提前感谢您的帮助! :)
解决方法
可能是依赖版本问题
尝试将其添加到您的 pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
然后删除 spring cloud 依赖项中指定的所有版本。例如
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。