To use an asynchronous EJB method, we need to create a session bean and configure it to have asynchronous methods. In the following code, we have an example of the implementation of a session bean called PdfHandler, which is responsible for saving PDF files on a filesystem:
import javax.ejb.AsyncResult;import javax.ejb.Asynchronous;import javax.ejb.Stateless;import java.io.IOException;import java.util.Date;import java.util.concurrent.Future;@Statelesspublic class PdfHandler { @Asynchronous public Future<String> handler (FileBean file) throws IOException { return new AsyncResult( FileSystemUtils.save( file.getFile(), "pdf", "pdf_"+ new Date().getTime() + ".pdf" )); }}
In the preceding code block, we have the PdfHandler class, ...