当线程在活动之前或活动期间处于正在等待、休眠或占用状态且该线程被中断时,抛出该异常。
产生原因是:使用JUnit测试xxlJob对应的excute方法时,同时启动了xxl-job对应的注册心跳线程,该心跳线程每隔30秒会向xxl-job对应的服务器发送一个消息,JUnit执行过程中产生Junit主线程,主线程执行完成之后会停止,xxl-job对应的从线程会被迫停止,抛出该异常
解决办法如下:
@ConditionalOnProperty(value = "xxl-job.enabled",havingValue = "true",matchIfMissing = true)
找到项目的
@Configuration
@ConditionalOnProperty(value = "xxl-job.enabled",havingValue = "true",matchIfMissing = true)
public class XxlJobConfig {
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobExecutor xxlJobExecutor() {
XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
//xxlJobExecutor.setIp(ip);
xxlJobExecutor.setPort(port);
xxlJobExecutor.setAppName(appname);
xxlJobExecutor.setAdminAddresses(adminAddresses);
xxlJobExecutor.setLogPath(logPath);
xxlJobExecutor.setAccessToken(accessToken);
return xxlJobExecutor;
}
}
在Junit的测试类中增加如下代码:
@SpringBootTest
public class APPTest {
static {
System.setProperty("xxl-job.enabled", "false");
}
@Test
void test1() {
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)