我在 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);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/414769.html
標籤:
上一篇:我無法在SpringBootTest中自動裝配服務類
下一篇:在單個類中使用多個事務的正確方法
