当前位置: 首页 > 知识库问答 >
问题:

Gracefull关闭Spring启动应用程序

薛修能
2023-03-14

我正在运行一个spring启动应用程序,除了尝试关闭它之外,一切都很好。我在下面的代码中出错

    while (true) {
        try {
            if(level2List == null)
                break;
            CDR cdr = level2List.poll(2, TimeUnit.SECONDS);

该错误在最后一行生成,spring boot将在2秒等待完成之前关闭level2List,如下所示

2015-05-29 17:32:15.758  INFO 27390 --- [       Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@358ee631: startup date [Fri May 29 17:31:17 GMT 2015]; root of context hierarchy
2015-05-29 17:32:15.765  INFO 27390 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2015-05-29 17:32:15.766  INFO 27390 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans
2015-05-29 17:32:15.780  INFO 27390 --- [       Thread-1] o.s.c.ehcache.EhCacheManagerFactoryBean  : Shutting down EhCache CacheManager
2015-05-29 17:32:15.804  INFO 27390 --- [       Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'level2ES'
2015-05-29 17:32:15.815  INFO 27390 --- [       Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'level1ES'
2015-05-29 17:32:15.823  INFO 27390 --- [       Thread-1] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2015-05-29 17:32:15.825  INFO 27390 --- [       Thread-1] com.jolbox.bonecp.BoneCP                 : Shutting down connection pool...
2015-05-29 17:32:15.833  INFO 27390 --- [       Thread-1] com.jolbox.bonecp.BoneCP                 : Connection pool has been shutdown.
2015-05-29 17:32:15.848 ERROR 27390 --- [pool-2-thread-1] c.t.t.c.process.CDRDataBase     : Error

java.lang.InterruptedException: null
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088)
        at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
        at com.teltacworldwide.tekram.cdrserver.process.CDRDataBaseNative.run(CDRDataBaseNative.java:79)
        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:483)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

是否有任何方法可以命令关闭过程,或确保在关闭之前我没有使用level2List?

沙布尔酒店

共有1个答案

长孙沈义
2023-03-14

我做了两件事

添加

@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskExecutor level1ES() {

也是

    } catch (InterruptedException e) {
        log.warn("Closing application while CDR still in queue");           }

沙布尔酒店

 类似资料:
  • 启动 1. 轻触主画面上您想启动的应用程序图标。 显示LiveArea™。 2. 轻触[开始]。 中断/继续 按下PS键即可返回LiveArea™。若要继续,请轻触[继续]。 关闭 1. 按下PS键。 返回LiveArea™。 2. 请由画面右上角将LiveArea™撕下。

  • 并且我有以下类: 当中的为时,它继续,否则,应用程序应该关闭,我们可以在bean创建期间关闭应用程序吗?这是一个好的做法吗?有什么好办法处理这件事吗?

  • 下面是我得到的audit4j:info初始化audit4j······audit4j:信息加载配置...AUDIT4J:信息验证配置...audit4j:info正在初始化处理程序...audit4j:info org.audit4j.core.handler.consoleAuditHandler已初始化。audit4j:info org.audit4j.core.handler.file.Fi

  • 我在kubernetes集群上尝试使用Helm Chart进行spring boot微服务部署。但我注意到一个奇怪的问题,我的spring boot应用程序启动后却立即关闭 这是我的头盔模板-