@Test public void task04() throws ExecutionException, InterruptedException { long now = System.currentTimeMillis(); logger.info("[task04][开始执行]"); ListenableFuture<Integer> execute01Result = demoService.execute01AsyncWithListenableFuture(); logger.info("[task04][execute01Result 的类型是：({})]",execute01Result.getClass().getSimpleName()); execute01Result.addCallback(new SuccessCallback<Integer>() { @Override public void onSuccess(Integer result) { logger.info("[onSuccess][result: {}]", result); } }, new FailureCallback() { @Override public void onFailure(Throwable ex) { logger.info("[onFailure][发生异常]", ex); } }); execute01Result.addCallback(new ListenableFutureCallback<Integer>() { @Override public void onSuccess(Integer result) { logger.info("[onSuccess][result: {}]", result); } @Override public void onFailure(Throwable ex) { logger.info("[onFailure][发生异常]", ex); } }); execute01Result.get(); logger.info("[task04][结束执行，消耗时长 {} 毫秒]", System.currentTimeMillis() - now); }
@Async public ListenableFuture<Integer> execute01AsyncWithListenableFuture() { try { return AsyncResult.forValue(this.execute02()); } catch (Throwable ex) { return AsyncResult.forExecutionException(ex); } }
DemoService { @Async public ListenableFuture<Integer> execute01AsyncWithListenableFuture() { try { return AsyncResult.forValue(this.execute02()); } catch (Throwable ex) { return AsyncResult.forExecutionException(ex); } } }
DemoService { @Async public ListenableFuture<Integer> execute01AsyncWithListenableFuture() { try { return AsyncResult.forValue(this.execute02()); } catch (Throwable ex) { return AsyncResult.forExecutionException(ex); } }  }
DemoService { @Async public ListenableFuture<Integer> execute01AsyncWithListenableFuture() { try { return AsyncResult.forValue(this.execute02()); } catch (Throwable ex) { return AsyncResult.forExecutionException(ex); } }  @Async Integer execute01Async(); @Async Integer execute02Async(); @Async Future<Integer> execute01AsyncWithFuture(); @Async Future<Integer> execute02AsyncWithFuture(); @Async ListenableFuture<Integer> execute01AsyncWithListenableFuture(); Integer execute01(); Integer execute02(); @Async Integer zhaoDaoNvPengYou(Integer a, Integer b); }
DemoService { @Async public ListenableFuture<Integer> execute01AsyncWithListenableFuture() { try { return AsyncResult.forValue(this.execute02()); } catch (Throwable ex) { return AsyncResult.forExecutionException(ex); } }  @Async Integer execute01Async(); @Async Integer execute02Async(); @Async Future<Integer> execute01AsyncWithFuture(); @Async Future<Integer> execute02AsyncWithFuture(); @Async ListenableFuture<Integer> execute01AsyncWithListenableFuture(); Integer execute01(); Integer execute02(); @Async Integer zhaoDaoNvPengYou(Integer a, Integer b);  }