mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 10:15:59 +00:00
fix[zfoo]: 优雅关闭服务器,避免bean财富回调shutdown方法
This commit is contained in:
1 parent
b0d8752f3d
commit
1377f8b4ce
5 files changed
+22
-39
No files matched your search
@@ -26,7 +26,6 @@ import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
@@ -49,13 +48,13 @@ public class EventContext implements ApplicationListener<ApplicationContextEvent
|
||||
return instance.applicationContext;
|
||||
}
|
||||
|
||||
public synchronized static void shutdown() {
|
||||
private synchronized void shutdown() {
|
||||
try {
|
||||
Field field = EventBus.class.getDeclaredField("executors");
|
||||
var field = EventBus.class.getDeclaredField("executors");
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
var executors = (ExecutorService[]) ReflectionUtils.getField(field, null);
|
||||
for (ExecutorService executor : executors) {
|
||||
for (var executor : executors) {
|
||||
ThreadUtils.shutdown(executor);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
||||
Reference in new issue
Block a user