// you will never know your task ran into an exception
@Test
public void test_executor_runnable() throws InterruptedException, ExecutionException {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
executor.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Scheduled One shot");
throw new IllegalArgumentException();
}
}, 1, TimeUnit.SECONDS);
executor.awaitTermination(2, TimeUnit.SECONDS);
}
// you will know your task ran into an exception
@Test
public void test_executor_runnable_process_exception() throws InterruptedException, ExecutionException {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
Future<?> future = executor.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Scheduled One shot");
throw new IllegalArgumentException();
}
}, 1, TimeUnit.SECONDS);
try {
future.get();
} catch (ExecutionException e) {
System.out.println(e);
}
}
@Test
public void test_executor_runnable() throws InterruptedException, ExecutionException {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
executor.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Scheduled One shot");
throw new IllegalArgumentException();
}
}, 1, TimeUnit.SECONDS);
executor.awaitTermination(2, TimeUnit.SECONDS);
}
// you will know your task ran into an exception
@Test
public void test_executor_runnable_process_exception() throws InterruptedException, ExecutionException {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
Future<?> future = executor.schedule(new Runnable() {
@Override
public void run() {
System.out.println("Scheduled One shot");
throw new IllegalArgumentException();
}
}, 1, TimeUnit.SECONDS);
try {
future.get();
} catch (ExecutionException e) {
System.out.println(e);
}
}