@Async public interface AsyncInterface { void doSomething(int i); Future<String> returnSomething(int i); }
@Async public static class AsyncClassListener implements ApplicationListener<ApplicationEvent> { public AsyncClassListener() { listenerConstructed++; } @Override public void onApplicationEvent(ApplicationEvent event) { listenerCalled++; assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); } }
@Async @Override public void doIt() { } }
@Async public static class AsyncClassBeanWithInterface implements RegularInterface { public void doSomething(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); } public Future<String> returnSomething(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); return new AsyncResult<>(Integer.toString(i)); } }
@Async @Override public void doIt() { } }
@Async @Override public Future<Object> failWithFuture() { throw new UnsupportedOperationException("failWithFuture"); }
@Async @Override public ListenableFuture<Object> failWithListenableFuture() { throw new UnsupportedOperationException("failWithListenableFuture"); }
@Async @Override public void failWithVoid() { throw new UnsupportedOperationException("failWithVoid"); }
@Override @Async public void test() { this.thread = Thread.currentThread(); this.latch.countDown(); }
@EventListener @Async public void handleAsync(AnotherTestEvent event) { collectEvent(event); if ("fail".equals(event.content)) { this.countDownLatch.countDown(); throw new IllegalStateException("Test exception"); } } }
@Async public CompletableFuture<String> returnSomethingCompletable(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (i == 0) { throw new IllegalArgumentException(); } return CompletableFuture.completedFuture(Integer.toString(i)); } }
@Async("e2") public Future<Thread> work3() { return new AsyncResult<>(Thread.currentThread()); } }
@Async public CompletableFuture<String> returnSomethingCompletable(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (i == 0) { throw new IllegalArgumentException(); } return CompletableFuture.completedFuture(Integer.toString(i)); }
@Override @Async public void onApplicationEvent(ApplicationEvent event) { listenerCalled++; assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); } }
@Async("e1") public void doSomething(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); assertTrue(Thread.currentThread().getName().startsWith("e1-")); }
@EventListener @Async public void handleAsync(AnotherTestEvent event) { assertTrue(!Thread.currentThread().getName().equals(event.content)); collectEvent(event); this.countDownLatch.countDown(); } }
@EventListener @Async public void handleAsync(AnotherTestEvent event) { assertTrue(!Thread.currentThread().getName().equals(event.content)); this.eventCollector.addEvent(this, event); this.countDownLatch.countDown(); } }
@EventListener @Async public void handleAsync(AnotherTestEvent event) { assertTrue(!Thread.currentThread().getName().equals(event.content)); this.eventCollector.addEvent(this, event); this.countDownLatch.countDown(); } }
@Async public ListenableFuture<String> returnSomethingListenable(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (i == 0) { throw new IllegalArgumentException(); } else if (i < 0) { return AsyncResult.forExecutionException(new IOException()); } return new AsyncResult<>(Integer.toString(i)); }
@Async public Future<String> returnSomething(int i) { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (i == 0) { throw new IllegalArgumentException(); } else if (i < 0) { return AsyncResult.forExecutionException(new IOException()); } return AsyncResult.forValue(Integer.toString(i)); }