title: Getting Spring scheduled tasks to run with the task executor thread
body: <p><strong>Background:</strong>  I use Spring 3.0.x in my Websphere 7 applications to grab the CommonJ WorkManager and TimerManager.  I use these to do arbitrary tasks at certain intervals in my deployed applications.</p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>I just learned that when setting a bean in the scheduler like so:</p>
  
  <pre><code>&lt;bean id="threadTest" class="test.ThreadTester" /&gt;
  
  &lt;task:scheduled-tasks scheduler="myTimerExecutor"&gt;
      &lt;task:scheduled ref="threadTest" method="execute" fixed-delay="300000" /&gt;
  &lt;/task:scheduled-tasks&gt;
  </code></pre>
  
  <p>In Websphere, it will run the <code>ThreadTester</code> class directly in the TimerManager thread pool.  This thread pool has a much higher priority (and fewer threads) than the WorkManager thread pool.  I want the thread to run with the WorkManager instead to be at the proper priority and use the proper resources set up for threads.</p>
  
  <p>As an alternative, instead of setting the bean in the scheduler like above, I can use the Spring <code>@Scheduled</code> annotation in the <code>ThreadTester</code> class like so:</p>
  
  <pre><code>@Scheduled(fixedDelay = 300000)
  public void execute() {
      ...
  }
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>Does using the <code>@Scheduled</code> annotation make the scheduled class run in the TimerManager thread pool or the WorkManager thread pool?</p>
  
  <p>If it runs using the WorkManager, then great!  That solves my problem.  However, if it is using the TimerManager to directly execute the class, then I guess I'll have to write some wrapper to correctly call the WorkManager.</p>
  
  <p>Thanks for any help!</p>
  
  <p><strong>Edit:</strong> Here I include how I set up the scheduler and executor with the Websphere 7 commonj implementations:</p>
  
  <pre><code>&lt;bean id="myTaskExecutor" 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="myTaskScheduler" 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;task:annotation-driven executor="myTaskExecutor" scheduler="myTaskScheduler" /&gt; 
  </code></pre>