簡體   English   中英

Spring引導應用程序的Gracefull關閉

[英]Gracefull shutdown for Spring boot Application

我正在運行一個spring-boot應用程序,一切都很好,除了我嘗試關閉它時。 我在以下代碼上出錯

    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?

沙伯

我做了兩件事

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

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

沙伯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM