title: Spring alternative to TimerService in EJB 3
body: <p>We're using EJB TimerService:s for controlling tasks that needs to be executed on demand or triggered via a cron expression some will run every night e.g. statistic collectors and some will run every 10s e.g. checking for new orders needed to be processed we must also be able to turn them on and off. It works fine most of the time but sometimes the the processes cannot be stopped and the only way to fix the problem is to flush the TimerPool and redeploy the application. </p>
  
  <p>I have been looking for a another solution of our problem and we have tried a version, with more controlling functionality , of the example below:
  <a href="http://www.adam-bien.com/roller/abien/entry/legally_starting_threads_in_ejbs" rel="nofollow noreferrer">http://www.adam-bien.com/roller/abien/entry/legally_starting_threads_in_ejbs</a></p>
  
  <p>It works fine but I've got the feeling we're pretty close to the boundary of how you should work with EJBs.</p>
  
  <p>I have been looking a Task Execution and Scheduling:
  <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html" rel="nofollow noreferrer">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html</a></p>
  
  <p>And it seems like a way to get rid of the EJB:s since we're only using them for the TimerService and the communication between the controller and the actual task. </p>
  
  <p>The problem is that I need more control than static configuration files and perhaps home brewed SchedulerFactoryBean would work but I don't really know where I should start looking? </p>
  
  <p><strong>Type of jobs</strong></p>
  
  <p><em>ProcessEngine</em></p>
  
  <ul>
  <li>Will be executed every 10s and check if there are any new customers and process their orders</li>
  <li>Should be able to turn the engine ON and OFF, either with soap or via a setting in the DB</li>
  </ul>
  
  <p><em>StatisticsCollector</em></p>
  
  <ul>
  <li>Should run every night at 3am by default</li>
  <li>Should be able to be triggered to run right now on demand</li>
  </ul>