How do you configure WorkManagers in WebLogic 10.3?

hallidave picture hallidave · Sep 24, 2009 · Viewed 17k times · Source

I would like to use a WorkManager to schedule some parallel jobs on a WebLogic 10.3 app server.

http://java.sun.com/javaee/5/docs/api/javax/resource/spi/work/WorkManager.html

I'm finding the Oracle/BEA documentation a bit fragmented and hard to follow and it does not have good examples for using WorkManagers from EJB 3.0.

Specifically, I'd like to know:

1) What exactly, if anything, do I need to put in my deployment descriptors (ejb-jar.xml and friends)?

2) I'd like to use the @Resource annotation to inject the WorkManager into my EJB 3 session bean. What "name" do I use for the resource?

3) How do I configure the number of threads and other parameters for the WorkManager.

My understanding is that the underlying implementation on WebLogic is CommonJ, but I'd prefer to use a non-proprietary approach if possible.

Answer

Pascal Thivent picture Pascal Thivent · Sep 25, 2009

First, you'll find the documentation of CommonJ, an implementation of the Timer and Work Manager API developed by BEA Oracle and IBM, in Timer and Work Manager API (CommonJ) Programmer’s Guide. They provide a Work Manager Example but it's not injected in this document.

1) What exactly, if anything, do I need to put in my deployment descriptors (ejb-jar.xml and friends)?

According to the Work Manager Deployment section:

Work Managers are defined at the server level via a resource-ref in the appropriate deployment descriptor. This can be web.xml or ejb-jar.xml among others.

The following deployment descriptor fragment demonstrates how to configure a WorkManager:

...
<resource-ref>
   <res-ref-name>wm/MyWorkManager</res-ref-name>
   <res-type>commonj.work.WorkManager</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
...

Note: The recommended prefix for the JNDI namespace for WorkManager objects is java:comp/env/wm.

Check the WorkManager javadocs for more details (e.g. "The res-auth and res-sharing scopes are ignored in this version of the specification. The EJB or servlet can then use the WorkManager as it needs to.").

2) I'd like to use the @Resource annotation to inject the WorkManager into my EJB 3 session bean. What "name" do I use for the resource?

I'd say something like this (not tested):

@ResourceRef(jndiName="java:comp/env/wm/MyWorkManager",
auth=ResourceRef.Auth.CONTAINER,
type="commonj.work.WorkManager",
name="MyWorkManager")

3) How do I configure the number of threads and other parameters for the WorkManager.

See the description of the <work-manager> element and Using Work Managers to Optimize Scheduled Work for detailed information on Work Managers

My understanding is that the underlying implementation on WebLogic is CommonJ, but I'd prefer to use a non-proprietary approach if possible.

I don't have any other suggestion (and, as long as this implementation follows the standards, I wouldn't mind using it).