如何在不阻止先前的Java 8的情况下等待异步ejb终止

时间:2018-10-06 21:36:08

标签: asynchronous java-7 java-ee-6 ejb-3.1

我需要一个具有异步方法的无状态ejb类,但在主类中,我需要调用一次或多次,而不是等待其终止而不阻塞。例如,我使用@Asynchronus并在完成时返回Future。.我想在主调用线程中等待完成,因此我必须在结果(Future)上使用get(),但我不想使用get()。我不想使用像CompletableFuture这样的Java 8解决方案,所以我想使用Callback类。如果我必须两次或多次调用此方法,则可能带有CountDown闩锁以等待所有被称为“线程”的线程。您知道我的上述解决方案可以使用JDK7和JEE6吗?

Would you like to play? [y/n]y
You rolled a 10
You rolled a 12

You lost! Would you like to play? [y/n]y
You rolled a 9
You rolled a 7

You lost! Would you like to play? [y/n]y
You rolled a 7

You won! Would you like to play? [y/n]y
You rolled a 6
You rolled a 10
You rolled a 3

You lost! Would you like to play? [y/n]y
You rolled a 8
You rolled a 9
You rolled a 11

You lost! Would you like to play? [y/n]n
Thanks for playing!
1 wins vs 4 lost 

谢谢! 罗比

0 个答案:

没有答案