June 2018
Intermediate to advanced
408 pages
11h 23m
English
Once asynchronous processing is enabled, then the methods that are annotated with the @Async annotation will execute asynchronously.
The following is a simple example of the @Async annotation:
public class AsyncTask { private static final Logger LOGGER = Logger.getLogger(AsyncTask.class); @Async public void doAsyncTask() { try { LOGGER.info("Running Async task thread : " + Thread.currentThread().getName()); } catch (Exception e) { } }}
We can also annotate the @Async annotation to a method with the return type, as follows:
@Async public Future<String> doAsyncTaskWithReturnType() { try { return new AsyncResult<String>("Running Async task thread : " + Thread.currentThread().getName()); } catch (Exception e) { }Read now
Unlock full access