[英]Spring 4 @Scheduled stops working
I am using @Scheduled annotation to run a cron job. 我正在使用@Scheduled注释来运行一个cron作业。 The scheduling works for some time, and then stops working.
调度工作一段时间,然后停止工作。 I will give simplified snippets of my code:
我将简化我的代码片段:
This is the scheduler: 这是调度程序:
//org.springframework.scheduling.annotation.Scheduled
@Scheduled("*/30 * * * * *")
public void performTask() {
logger.info("Starting agent");
getAgentAsyncTask().execute();
logger.info("Ending agent");
}
This is the task which is executed by scheduler 这是由调度程序执行的任务
//org.springframework.scheduling.annotation.Async
@Async(TASK_EXECUTOR)
@Override
public void execute() {
logger.info("Starting task");
//send some rest requests
logger.info("Ending task");
}
Both: "Starting agent" and "Ending agent" are logged equal number of times. 两者:“起始代理”和“结束代理”被记录的次数相等。 So, each scheduling is ending properly.
因此,每个调度都正确结束。
Both: "Starting task" and "Ending task" are logged equal number of times. 两者:“启动任务”和“结束任务”被记录的次数相等。 So, definitely, "task" is not blocking things.
所以,当然,“任务”并不是阻挡事物。
But it just stops logging after some time. 但它只是在一段时间后停止记录。 What might be the issue?
可能是什么问题?
Here, TASK_EXECUTOR is the following bean: 这里,TASK_EXECUTOR是以下bean:
@Bean(TASK_EXECUTOR)
public ThreadPoolTaskExecutor createDefaultTaskExecutor() {
ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
te.setMaxPoolSize(15);
te.setCorePoolSize(15);
te.initialize();
return te;
}
Spring version: 春季版:
4.1.6.RELEASE
4.1.6.RELEASE
Such a situation might be caused by an infinite loop in the body of the scheduled method or if there is a call to an external system and the control waits synchronously to receive the response without any timeout. 这种情况可能是由调度方法体内的无限循环引起的,或者是否有对外部系统的调用,并且控件同步等待接收响应而没有任何超时。
Try it by yourself with this simple code snippet. 使用这个简单的代码片段自己尝试一下。 The method will be started only once and will not be started after the specified interval of 5 seconds.
该方法仅启动一次,并且在指定的5秒间隔后不会启动。
@Scheduled(fixedRate = 5000)
public void printPeriodically() {
System.out.println("This is my periodic method");
while(true) {};
}
see whether job is getting hanged or not. 看工作是否被绞死。 incase if it does.. the task will not execute after some time i mean after reaching max pool size.
如果它确实...任务将在一段时间后执行,我的意思是在达到最大池大小后。 check you implementation code whether threads are released after successful execution.
检查实现代码是否在成功执行后释放线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.