环境:java version "1.7.0_67"
private static final long INITIAL_DELAY = 1000L;
private static final long DELAY = 500L;
private ScheduledExecutorService scheduledFullExecutorService = Executors.newSingleThreadScheduledExecutor();
@PostConstruct
public void init() {
scheduledFullExecutorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
function();
}, INITIAL_DELAY, DELAY, TimeUnit.MILLISECONDS);
}
如果function()出现未捕获的异常,导致scheduledFullExecutorService不能进行任务调度
测试方法:
function() {
if (true) {
throw new RuntimeException("test");
}
// code
...
}
private static final long INITIAL_DELAY = 1000L;
private static final long DELAY = 500L;
private ScheduledExecutorService scheduledFullExecutorService = Executors.newSingleThreadScheduledExecutor();
@PostConstruct
public void init() {
scheduledFullExecutorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
function();
}, INITIAL_DELAY, DELAY, TimeUnit.MILLISECONDS);
}
如果function()出现未捕获的异常,导致scheduledFullExecutorService不能进行任务调度
测试方法:
function() {
if (true) {
throw new RuntimeException("test");
}
// code
...
}