Need sample code explaning Workmanager in Tomcat

4.7k Views Asked by At

I want to know how to use WorkManager in Tomcat 7. I came across the open source library Foo-CommonJ but nowhere i found a sample code explaning the usage. The input parameter for FooWorkManager's constructor is an instance of commonj.work.work class, where as no one provides the commonj.work.work class (neither tomcat nor foo-commonj). Basically i need a sample code explaining usage of WorkManager (FooCommonj jar) in tomcat. And if Foo-Commonj doesn't support workmanager properly, then some alternative.

2

There are 2 best solutions below

0
On

JSR-237 has been withdrawn, but it has been merged with JSR-236. http://jcp.org/en/jsr/detail?id=237 Reason: JSR 237 has been merged with JSR 236, providing a single, consistent specification for Java EE concurrency.

0
On

Old school way

Copy to tomcat\lib folder following jars:

  • commonj-xxx.jar
  • tomcat-commonj-xxx.jar

In context.xml of your app or tomcat create a new WorkManager instance:

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

Fetch this instance using JNDI. For example using web.xml:

<resource-ref>
  <description>Work manager example</description>
  <res-ref-name>wm/myWorkManager"</res-ref-name>
  <res-type>commonj.work.WorkManager</res-type>
  <res-auth>Container</res-auth>
  <res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

Any other way should work.