•The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread; or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.
- EJB Spec
If you HAVE TO use multi threading, i can think of the following options.
1. Use JMS messages to achieve asynchronous job invocation, this is a better approach than the second. (There are MANY tutorials online to do this)
2. Separate your "multi threadedness" into a separate layer outside of your EJB layer. You might want to use a java job scheduler
to handle some of the headaches.
3. If you are running under Weblogic or Websphere, i heard they were working on a "Work Manager" specification. That might help you. I am not sure if it is under JCP. I think even JBoss supports it, but confirm.
The second option also puts u in a LOT of other headaches. Since the jobs will run in different threads, you will NOT have the security context or the transaction context propagated. You might be better off invoking other EJBs from the jobs so that you are under transactions again. I am not exactly sure how you would propagate the security context unless you endup using JAAS or something.