我在收到 SIGTERM 命令后实现了 SpringBoot 应用程序的正确终止。设置 SpringBoot 的设置:
server:
shutdown: graceful
spring.task.execution:
pool:
allow-core-thread-timeout: true
keep-alive: 3m
shutdown:
await-termination: true
await-termination-period: 3m
我还尝试使用 ThreadPoolTaskExecutor:
ThreadPoolTaskExecutor defaultExecutor = new ThreadPoolTaskExecutor();
defaultExecutor.setKeepAliveSeconds(180);
defaultExecutor.setWaitForTasksToCompleteOnShutdown(true);
defaultExecutor.setAwaitTerminationSeconds(180);
但遇到了问题。在异步线程中调用 SOAP 方法,该方法崩溃并出现错误:
ERROR [iso20022.app.FCR,3b58933b54e5e47c,1eb7da1d0650e9d9] 2808 --- [ h2h-async1] r.a.h.c.RepeaterInvocationHandler : error on calling jdk.proxy6.$Proxy236.wsAccountBaseInfoGet
java.lang.ExceptionInInitializerError: null
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.getTransport(HttpTransportPipe.java:154) ~[jaxws-rt-2.3.1.jar:2.3.1]
…
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1432)
at org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1140)
at javax.xml.bind.ContextFinder.firstByServiceLoaderDeprecated(ContextFinder.java:620)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:408)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
at com.sun.xml.ws.transport.http.client.HttpClientTransport.<clinit>(HttpClientTransport.java:84)
... 83 more
在此方法之前,feign 客户端通过 REST 搜索并保存到数据库,没有任何问题。该错误只能用 catch(Error e) 捕获,因为 Exception 不会被捕获。如果有人遇到类似的,提示去哪里挖?