ScheduledThreadPoolExecutor pe=new ScheduledThreadPoolExecutor(2);
Task task = new Task();
pe.scheduleAtFixedRate(task,0, 10, TimeUnit.SECONDS);
Task类
public class Task implements Runnable {
@Override
public void run() {
try {
System.out.println("Task:" + Thread.currentThread());
System.out.println("发送完毕");
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
}
}}为什么执行的时候遇到异常没有停止还是在执行呢
API里面是这样说的
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.小弟的理解就是说这个方法里面的一次遇到了异常就不会在周期性执行了,但是结果却还是执行,请大神们指点!!!!
Task task = new Task();
pe.scheduleAtFixedRate(task,0, 10, TimeUnit.SECONDS);
Task类
public class Task implements Runnable {
@Override
public void run() {
try {
System.out.println("Task:" + Thread.currentThread());
System.out.println("发送完毕");
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
}
}}为什么执行的时候遇到异常没有停止还是在执行呢
API里面是这样说的
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.小弟的理解就是说这个方法里面的一次遇到了异常就不会在周期性执行了,但是结果却还是执行,请大神们指点!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货