Result retrieval mode

In this mode, a method will be configured with a return type by wrapping the result with the Future type:

@Service
public class BankAsyncService {

private static final Logger LOGGER =
Logger.getLogger(BankAsyncService.class);

@Async
public Future<String> syncCustomerAccount() throws
InterruptedException {
LOGGER.info("Sync Account Processing Started - Thread id: " +
Thread.currentThread().getId());

Thread.sleep(2000);

String processInfo = String.format("Sync Account Processing
Completed - Thread Name= %d, Thread Name= %s",
Thread.currentThread().getId(),
Thread.currentThread().getName());

LOGGER.info(processInfo);

return new AsyncResult<String>(processInfo);
}
}

Spring also provides support for the AsyncResult class, which implements the Future interface. It can be used to track the result of asynchronous method invocation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset