title: Work Managers for EJB Parallel Processing
body: <p>I need to parallelize the asynchronous invocation of several different EJBs, in each one I need to call a transactional method. I'm using a clustered installation of WebLogic as my deployment environment, and ideally I'd like to distribute the workload across different threads in different nodes of the cluster.</p>
  
  <p>After finding <a href="https://stackoverflow.com/questions/2005934/how-can-an-ejb-parallelize-a-long-cpu-intensive-process">previous</a> <a href="https://stackoverflow.com/questions/533783/why-spawning-threads-in-java-ee-container-is-discouraged?lq=1">posts</a> on the subject I guess that using Work Managers might be a viable alternative for my environment, but after reading the <a href="http://docs.oracle.com/cd/E15523_01/web.1111/e13733/toc.htm#i1058123" rel="nofollow noreferrer">documentation</a> I'm left with a couple of questions, I'd be very thankful if someone with more experience using Work Managers can shed some light on these:</p>
  
  <ol>
  <li>Is it possible to implement the <code>Work</code> interface in an EJB, in such a way that when the <code>run()</code> method gets called, it can invoke one of the transactional methods of that EJB? I'm interested in asynchronously and concurrently invoking several EJBs, each one representing a different unit of work, but I don't know if the Work Manager will propagate the required execution context to my EJBs.</li>
  <li>If I configure a global Work Manager, when I use it does it take care of automatically distributing the workload across all the nodes in my cluster? or all the Works sent to it will be executed in the same cluster node, although in different threads? - if that's the case, how could I parallelize my workload in such a way that all the nodes in my cluster get their share of the work?</li>
  </ol>
  
  <p>Also, it'd be great if someone can suggest a different alternative (instead of using Work Managers), as long as the requirements in the first paragraph of this question are met.</p>