Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是对 Spring 框架中的异步可能性进行了一些试验,并且我在问自己如何在异步函数调用完成时获得通知。是否有任何回调功能或类似的东西?
您可以让您的@Async方法返回 aFuture通过它可以获得返回值:
@Async
Future
@Async public Future<Something> findSomethingAsync( final int id ) { Something s = ... return new AsyncResult<Something>( s ); }
一旦 async 方法完成,Future'isDone()方法就会为真,你可以future.get()得到结果。
isDone()
future.get()
干杯,