I use Java and Spring Boot. I implemented the correct termination of the application when receiving the SIGTERM command.
Set the settings for SpringBoot:
server:
shutdown: graceful
spring.task.execution:
pool:
allow-core-thread-timeout: true
keep-alive: 3m
shutdown:
await-termination: true
await-termination-period: 3m
And I also tried it with ThreadPoolTaskExecutor
:
ThreadPoolTaskExecutor defaultExecutor = new ThreadPoolTaskExecutor();
defaultExecutor.setKeepAliveSeconds(180);
defaultExecutor.setWaitForTasksToCompleteOnShutdown(true);
defaultExecutor.setAwaitTerminationSeconds(180);
But I ran into a problem. In an asynchronous thread, the SOAP method is called and it crashes with an error:
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) ~[tomcat-embed-core-9.0.76.jar:9.0.76]
at org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1140) ~[tomcat-embed-core-9.0.76.jar:9.0.76]
at javax.xml.bind.ContextFinder.firstByServiceLoaderDeprecated(ContextFinder.java:611) ~[jaxb-api-2.4.0-b180830.0359.jar:2.3.0]
Please, help. What do I need to do?
The problem was in the libraries.
Was:
implementation group: 'org.glassfish.main.javaee-api', name: 'javax.jws', version: '3.1.2.2'
implementation group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1'
implementation group: 'com.sun.xml.ws', name: 'jaxws-rt', version: '2.3.1'
Need to do:
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'jakarta.xml.ws:jakarta.xml.ws-api:4.0.0'
implementation 'jakarta.activation:jakarta.activation-api:2.1.2'
implementation 'com.sun.xml.ws:jaxws-rt:4.0.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.2'
runtimeOnly 'jakarta.xml.soap:jakarta.xml.soap-api:3.0.0'
runtime Only 'com.sun.xml.messaging.saaj:saaj-impl:3.0.2'
And accordingly, fix the imports in the classes from javax to jakarta