CommonJ
Overview
Install
Tuning
Download
Javadoc
JSR 236 Javadoc
JSR 237 Javadoc

CommonJ − Install

Download the binary distribution and place the jars in the WEB-INF/lib directory of your web application.

Configuring the JNDI Resource

The definition of JNDI resources is vendor specific. For Tomcat you have to add a Resource element to the Context definition of your web application. For details please look here. The following defines a WorkManager named MyWorkManager that uses up to 5 concurrent threads:

<Context ...>
	...
	<Resource name="wm/MyWorkManager" 
		auth="Container"
		type="commonj.work.WorkManager"
		factory="de.myfoo.commonj.work.FooWorkManagerFactory" 
		maxThreads="5" />
	...
</Context>		

Please look at the tuning section for a list of all configuration parameters.

Declare Your Resource Requirements

Applications signal their need for a work manager by including a resource-ref in the deployment descriptor (web.xml). The suggested name prefix for the JNDI namespace for WorkManager objects is java:comp/env/wm.

The following provides an example resource-ref fragment configuring a WorkManager named MyWorkManager:

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

Lookup a Work Manager

The following example shows the WorkManager being looked up in JNDI:

import commonj.work.*;
...
try {
	InitialContext ctx = new InitialContext();
	WorkManager mgr = (WorkManager) ctx.lookup("java:comp/env/wm/MyWorkManager");
}
catch (Exception e) {
	...
}