views:

2601

answers:

1

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.

+2  A: 

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).

Pascal Thivent
It looks like 1) and 2) are two different versions of the same thing? I'm assuming you only need to do 2) is a pure EJB 3 app?
hallidave
I think so too. But I did test 1), not 2)
Pascal Thivent