Is there a way to run multiple threads inside a single EJB execution?
What I'm trying to do is essentially an ETL process: the onMessage
method of an MDB (@MessageDriven
) will run a query, then kick off multiple threads to insert rows into some target table (all native JDBC, not JPA.)
It could just as easily be a @Stateless
session bean as well.
The question is - Can you use Executors.newFixedThreadPool
inside an EJB? Even if it's not strictly legal according to spec, can you get away with it if the background threads are not accessing any Java EE / container-managed resources?
If not, is there a better way to do this? I know about @Async
but would lose control over the number of allowed threads per job.