我在 Spring Boot 中运行以下调度程序。crontab 时间设定为每分钟执行该方法。然后我尝试阻止该方法 1.5 分钟。我观察到,该方法不会在第一次执行的下一分钟执行,直到回圈执行 1.5 分钟。我认为它以异步方式作业。现在很迷茫!春季调度程序是阻塞呼叫吗?
@Override
@Scheduled(cron = "0 0/1 * * * ?")
//@SchedulerLock(name = "test")
public void test()
{
System.out.println("test scheduler enters:" LocalDateTime.now());
//LockAssert.assertLocked();
//System.out.println("now locked\n");
long st=System.currentTimeMillis();
while(true)
{
long diff=(System.currentTimeMillis()-st)/1000;
if(diff>90)
{
System.out.println("breaking time:" (System.currentTimeMillis()-st)/1000 ", timeNow:" LocalDateTime.now());
break;
}
}
System.out.println("Out of the loop");
}
uj5u.com热心网友回复:
如
您可以通过例如(取自此处)配置多个执行绪:
@Configuration
@EnableScheduling
public class AppConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(destroyMethod="shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(100);
}
}
0 评论