Implementing EJBs
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; @Stateless public 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, which contains a handler(FileBean file)
method. This method is annotated with @Asynchronous
to configure it as an asynchronous method.
The following code demonstrates the configuration of the handle...