O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Result retrieval mode

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

@Servicepublic 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required