我为 RejectedExecutionException 的测试处理创建了调度程序:
@Component
public class TestScheduler {
private final TestService testService;
private ExecutorService executorService;
public TestScheduler(TestService testService) {
this.testService = testService;
}
@PostConstruct
public void init() {
executorService = Executors.newFixedThreadPool(5);
}
@Scheduled(fixedRate = 10L)
public void test() {
System.out.println("test");
executorService.execute(testService::print);
}
}
和延迟 70 秒的服务:
@Component
public class TestService {
public void print() {
System.out.println("print start");
try {
TimeUnit.SECONDS.sleep(70);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("print end");
}
}
我等待下一个逻辑:
调度程序调用executorService.execute(testService::print)5 次
每个testService::print将执行 70 秒
当execute方法第六次调用我得到RejectedExecutionException
但我没有得到异常。我有这个日志:
test
print start
2018-10-22 11:26:45.543 INFO 5960 --- [ main] c.e.s.SchedullerExceptionsApplication : Started SchedullerExceptionsApplication in 0.661 seconds (JVM running for 1.108)
test
print start
test
print start
test
print start
test
print start
test
...
70 seconds print test
拉莫斯之舞
猛跑小猪
牛魔王的故事
随时随地看视频慕课网APP
相关分类