title: Using a CommonJ implementation with GlassFish and Spring 3
body: <p>In my quest to unify deployment among Websphere 7 and GlassFish 3 environments, I decided to try implementing a CommonJ WorkManager and TimerManager in GlassFish.  But it isn't quite working as expected.  I have done the following:</p>
  
  <p>Use the myFOO CommonJ implementation found at: <a href="http://commonj.myfoo.de/" rel="nofollow">http://commonj.myfoo.de/</a> and include the libraries into my domain/lib folder (including the Spring libs)</p>
  
  <p>Added the following to the <code>&lt;resources&gt;</code> section of the glassfish domain.xml:</p>
  
  <pre><code>&lt;custom-resource res-type="commonj.work.WorkManager" jndi-name="wm/default" factory-class="de.myfoo.commonj.work.FooWorkManagerFactory"&gt;&lt;/custom-resource&gt;
  &lt;custom-resource res-type="commonj.timers.TimerManager" jndi-name="tm/default" factory-class="de.myfoo.commonj.timers.FooTimerManagerFactory"&gt;&lt;/custom-resource&gt;
  </code></pre>
  
  <p>Include the references in the <code>&lt;servers&gt;</code>/<code>&lt;server&gt;</code> section of the domain.xml:</p>
  
  <pre><code>  &lt;resource-ref ref="wm/default"&gt;&lt;/resource-ref&gt;
    &lt;resource-ref ref="tm/default"&gt;&lt;/resource-ref&gt;
  </code></pre>
  
  <p>Add the appropriate resource references in the web.xml of my test application:</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;description&gt;WorkManager&lt;/description&gt;
      &lt;res-ref-name&gt;wm/default&lt;/res-ref-name&gt;
      &lt;res-type&gt;commonj.work.WorkManager&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;
  &lt;/resource-ref&gt;
  
  &lt;resource-ref&gt;
      &lt;description&gt;TimerManager&lt;/description&gt;
      &lt;res-ref-name&gt;tm/default&lt;/res-ref-name&gt;
      &lt;res-type&gt;commonj.timers.TimerManager&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;res-sharing-scope&gt;Unshareable&lt;/res-sharing-scope&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>Add the following beans to my applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="threadTestTaskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor"&gt; 
      &lt;property name="workManagerName" value="wm/default" /&gt;
      &lt;property name="resourceRef" value="true"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="threadTestTimerExecutor" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler"&gt; 
      &lt;property name="timerManagerName" value="tm/default" /&gt;
      &lt;property name="resourceRef" value="true" /&gt;
      &lt;property name="shared" value="false" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="threadTest" class="test.ThreadTester"&gt;&lt;/bean&gt;
  
  &lt;task:scheduled-tasks scheduler="threadTestTimerExecutor"&gt;
      &lt;task:scheduled ref="threadTest" method="execute" fixed-delay="30000" /&gt;  &lt;!-- 30 seconds --&gt;
  &lt;/task:scheduled-tasks&gt;
  </code></pre>
  
  <p>After all of this set-up, everything loads find and the web application runs; however, the ThreadTester class does not run on the Timer.</p>
  
  <p>I have stepped through the myFOO code and the TimerManager (FooTimerManager.java) main loop is running, it just never seems to recognize that every 30 seconds it's supposed to launch the class.</p>
  
  <p>My questions:</p>
  
  <p><strong>Has anyone had experience implementing JSR 236/237 (CommonJ) with GlassFish 3 and Spring?</strong>  </p>
  
  <p>Is there another implementation somewhere other than myFOO that I could use and try out?
  Has anyone attempted to do what I've done?  Would you be willing to share your results if you succeeded?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>I forgot to mention that using myFOO CommonJ implementation with GlassFish <strong>does</strong> work as far as the WorkManager is concerned.  What does <strong>not</strong> work is the TimerManager.  This means that I can launch threads on demand just fine but triggered scheduling doesn't work.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Since updating to GlassFish 3.1.1, the myFOO CommonJ implementation of the TimerManager is working fine.  So... great!  This question is now more like a HOWTO Guide.</p>