public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
现假设有3个任务需要去处理,分别对应AsyncTask类的taskOne、taskTwo、taskThree方法,这里做了线程的sleep来模拟实际运行。
@Slf4j
@Component
public class AsyncTask {
private Random random = new Random();
public void taskOne() throws InterruptedException {
long start = System.currentTimeMillis();
Thread.sleep(random.nextInt(10000));
long end = System.currentTimeMillis();
log.info(“任务一执行完成耗时{}秒”, (end - start)/1000f);
}
public void taskTwo() throws InterruptedException {
long start = System.currentTimeMillis();
Thread.sleep(random.nextInt(10000));
long end = System.currentTimeMillis();
log.info(“任务二执行完成耗时{}秒”, (end - start)/1000f);
}
public void taskThree() throws InterruptedException {