@Test public void testAsyncWithFuture() { Future<String> result = asyncService.asyncWithResult(); try { assertTrue(result.get().equals("hi springboot async")); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
@Async("customFixedThreadPool") public Future<String> asyncWithResult() { try { Thread.sleep(2*1000); log.info("hi,springboot async with return value," +Thread.currentThread().getName()); return new AsyncResult<String>("hi springboot async"); } catch (InterruptedException e) { e.printStackTrace(); } return null; }
AsyncService { @Async("customFixedThreadPool") public Future<String> asyncWithResult() { try { Thread.sleep(2*1000); log.info("hi,springboot async with return value," +Thread.currentThread().getName()); return new AsyncResult<String>("hi springboot async"); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }
AsyncService { @Async("customFixedThreadPool") public Future<String> asyncWithResult() { try { Thread.sleep(2*1000); log.info("hi,springboot async with return value," +Thread.currentThread().getName()); return new AsyncResult<String>("hi springboot async"); } catch (InterruptedException e) { e.printStackTrace(); } return null; }  }
AsyncService { @Async("customFixedThreadPool") public Future<String> asyncWithResult() { try { Thread.sleep(2*1000); log.info("hi,springboot async with return value," +Thread.currentThread().getName()); return new AsyncResult<String>("hi springboot async"); } catch (InterruptedException e) { e.printStackTrace(); } return null; }  @Async void asyncHello(); @Async("customFixedThreadPool") void async1(); @Async("customFixedThreadPool") Future<String> asyncWithResult(); }
AsyncService { @Async("customFixedThreadPool") public Future<String> asyncWithResult() { try { Thread.sleep(2*1000); log.info("hi,springboot async with return value," +Thread.currentThread().getName()); return new AsyncResult<String>("hi springboot async"); } catch (InterruptedException e) { e.printStackTrace(); } return null; }  @Async void asyncHello(); @Async("customFixedThreadPool") void async1(); @Async("customFixedThreadPool") Future<String> asyncWithResult();  }