mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-06 04:24:08 +00:00
style[code]: code style
This commit is contained in:
@@ -47,6 +47,18 @@ public class EventContext implements ApplicationListener<ApplicationContextEvent
|
||||
return instance.applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationContextEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent) {
|
||||
// 初始化上下文
|
||||
EventContext.instance = this;
|
||||
instance.applicationContext = event.getApplicationContext();
|
||||
} else if (event instanceof ContextClosedEvent) {
|
||||
shutdown();
|
||||
ThreadUtils.shutdownForkJoinPool();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void shutdown() {
|
||||
try {
|
||||
var field = EventBus.class.getDeclaredField("executors");
|
||||
@@ -64,18 +76,6 @@ public class EventContext implements ApplicationListener<ApplicationContextEvent
|
||||
logger.info("Event shutdown gracefully.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationContextEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent) {
|
||||
// 初始化上下文
|
||||
EventContext.instance = this;
|
||||
instance.applicationContext = event.getApplicationContext();
|
||||
} else if (event instanceof ContextClosedEvent) {
|
||||
shutdown();
|
||||
ThreadUtils.shutdownForkJoinPool();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 30;
|
||||
|
||||
@@ -43,10 +43,10 @@ public class SchedulerContext implements ApplicationListener<ApplicationContextE
|
||||
|
||||
private static SchedulerContext instance;
|
||||
|
||||
private static boolean stop = false;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private volatile boolean stop = false;
|
||||
|
||||
|
||||
public static SchedulerContext getSchedulerContext() {
|
||||
return instance;
|
||||
@@ -57,30 +57,9 @@ public class SchedulerContext implements ApplicationListener<ApplicationContextE
|
||||
}
|
||||
|
||||
public static boolean isStop() {
|
||||
return stop;
|
||||
return instance.stop;
|
||||
}
|
||||
|
||||
|
||||
public synchronized static void shutdown() {
|
||||
if (stop) {
|
||||
return;
|
||||
}
|
||||
|
||||
stop = true;
|
||||
|
||||
try {
|
||||
Field field = SchedulerBus.class.getDeclaredField("executor");
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
var executor = (ScheduledExecutorService) ReflectionUtils.getField(field, null);
|
||||
ThreadUtils.shutdown(executor);
|
||||
} catch (Throwable e) {
|
||||
logger.error("Scheduler thread pool failed shutdown.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Scheduler shutdown gracefully.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationContextEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent) {
|
||||
@@ -141,6 +120,26 @@ public class SchedulerContext implements ApplicationListener<ApplicationContextE
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static void shutdown() {
|
||||
if (isStop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance.stop = true;
|
||||
|
||||
try {
|
||||
Field field = SchedulerBus.class.getDeclaredField("executor");
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
var executor = (ScheduledExecutorService) ReflectionUtils.getField(field, null);
|
||||
ThreadUtils.shutdown(executor);
|
||||
} catch (Throwable e) {
|
||||
logger.error("Scheduler thread pool failed shutdown.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Scheduler shutdown gracefully.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
Reference in New Issue
Block a user