I’m learning Java EE currently (moving from SE) and I am confused about asynchronous execution in Java EE environment.
Basically what I understand creating Thread or Timer is not exactly recommended. One other method what I found so far are use JMS for transfer message to EJB Message Bean and it will be executed asynchronously.
What are some other methods to achieve this behavior? Cause using JMS looks like too much overhead for simple tasks.
The simplest possible solution in Java EE 6 is to use
@Asynchronousannotation on your EJB method (or the whole class). It allows you to invoke a business method asynchronously which means that a new thread will be delegated to execute this method and you’ll get the control back in caller method.In pre-Java EE 6 days the JMS was used for this purpose.
As a side note – in Servlets you can also use asynchronous execution.