1
我需要做的是onething我不知道至極就是對此最好的做法。春任務異步和延遲
在我向特定服務發送一個請求後,這個返回OK並排隊我的請求。我有一個回調服務,用於通知何時結束。
問題是,整個過程可能需要很長時間而不通知任何事情,之後我需要考慮超時。
該應用程序是SpringBoot APP,我正考慮在帶睡眠時間的服務方法上使用註釋@EnableAsync和@Async。
@Configuration
@EnableAsync
public class AsyncConfiguration implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("TIMCLL-");
executor.initialize();
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
// TODO Auto-generated method stub
return null;
}
}
。 。 。
@Async
public void verifyStatusTimPayment() throws InterruptedException {
Thread.sleep(5000);
logger.info("Executed after 5s " + new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format(new Date()));
}
驗證需要在請求後15分鐘完成,並且每個請求只發生一次。
我怎麼能做到這一點,而不做出了Thread.sleep ?????