Yes, JMS might be an option. You simply send a message to a queue, and a Message Driven Bean -- a special kind of EJB -- will then receive and process the message. The message acts in this case like a command. You can use JMS without Message Driven Bean though, but it's a bit more complicated.
If you are in a EJB 3.1 environment, you could give a try to asynchronous EJB.
Otherwise, while it's not recommended by the spec, you could start a thread in the web container. Either you start one thread per job, or you could start/stop one background thread in a ServletContextListener
, which processes commands that you store, say, in a table in a database.
Using asynchronous jobs is superficially very easy, but for production you will need to think about how to manage error, monitor progress, retry failed job, ensure that no two same job are run at the same time, etc. Each approach has its own strength and weakness. Pay also attention to the strategy you need for the transactions (JMS is transacted, I don't know exactly for async EJB 3.1., and custom thread and database table can be transacted if do things correctly with JDBC transaction or UserTransaction
).
Hope it helps.