环境 xxl-job 2.2.0 ,springboot版本 2.3.1.RELEASE, 调度器启动正常
执行器启动始终会在destroy() 方法报错,registryThread空指针
18:20:34.102 logback [main] INFO c.e.demo.ChahuashiServiceApplication - Started ChahuashiServiceApplication in 0.954 seconds (JVM running for 1.657)
18:20:34.106 logback [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'applicationTaskExecutor'
18:20:34.110 logback [SpringContextShutdownHook] ERROR c.x.job.core.executor.XxlJobExecutor - null
java.lang.NullPointerException: null
at com.xxl.job.core.thread.ExecutorRegistryThread.toStop(ExecutorRegistryThread.java:117)
at com.xxl.job.core.server.EmbedServer.stopRegistry(EmbedServer.java:262)
at com.xxl.job.core.server.EmbedServer.stop(EmbedServer.java:124)
at com.xxl.job.core.executor.XxlJobExecutor.stopEmbedServer(XxlJobExecutor.java:158)
at com.xxl.job.core.executor.XxlJobExecutor.destroy(XxlJobExecutor.java:85)
at com.xxl.job.core.executor.impl.XxlJobSpringExecutor.destroy(XxlJobSpringExecutor.java:57)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:258)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:579)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:551)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1089)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:512)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1082)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1061)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1030)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:949)
18:20:34.110 logback [xxl-job, executor JobLogFileCleanThread] INFO c.x.j.c.thread.JobLogFileCleanThread - >>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.
18:20:34.110 logback [xxl-job, executor TriggerCallbackThread] INFO c.x.j.c.thread.TriggerCallbackThread - >>>>>>>>>>> xxl-job, executor callback thread destory.
18:20:34.110 logback [Thread-80] INFO c.x.j.c.thread.TriggerCallbackThread - >>>>>>>>>>> xxl-job, executor retry callback thread destory.
Process finished with exit code 0
反复断点调试,发现debug时,在start()方法内稍作停留即可避免执行destroy()时空指针,于是最简单的解决方法就有了。
修改核心模块的 com.xxl.job.core.executor.impl.XxlJobSpringExecutor,在start()方法后添加延迟
// start
@Override
public void afterSingletonsInstantiated() {
// init JobHandler Repository
/*initJobHandlerRepository(applicationContext);*/
// init JobHandler Repository (for method)
initJobHandlerMethodRepository(applicationContext);
// refresh GlueFactory
GlueFactory.refreshInstance(1);
// super start
try {
super.start();
//延迟1s,解决执行器destroy()空指针报错
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// destroy
@Override
public void destroy() {
super.destroy();
}
后续来了
之前XxlJobSpringExecutor 注册Bean没加serAddress,以为默认为空自动获取,后来加上了xxlJobSpringExecutor.setAddress(address); 再没遇见上述错误,具体实现以后再看吧,先把这坑填了
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
//调用核心方法包的xxlJobSpringExecutor类
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setAddress(address);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}