[jboss-user] [JBoss Seam] - Re: Start quartz cron when Seam apps is up

cavani do-not-reply at jboss.com
Mon Jan 14 06:42:41 EST 2008


I am using this:


  | 
  | @Name("bootstrap")
  | @Scope(ScopeType.APPLICATION)
  | @BypassInterceptors
  | @Startup
  | public class Bootstrap
  | {
  | 
  | 	@Create
  | 	public void start() throws Exception
  | 	{
  | 		Events.instance().raiseTimedEvent("comeEvent", new CronSchedule((Long) null, "0 0 6 * * ?"));
  | 	}
  | 
  | 	@Destroy
  | 	public void stop()
  | 	{
  | 	}
  | 
  | }
  | 

It's working, but may not be exactly what you want.

Other way (once setted you can't get cron trigger anymore, so...):


  | @Name("synchronizationTimer")
  | @Scope(ScopeType.APPLICATION)
  | @Startup
  | public class SynchronizationTimer
  | {
  | 
  | 	private static final String defaultTrigger = "0 0 3 * * ?";
  | 
  | 	@Logger
  | 	private Log log;
  | 
  | 	private QuartzTriggerHandle handle;
  | 
  | 	private String trigger = defaultTrigger;
  | 
  | 	@Create
  | 	public void start() throws Exception
  | 	{
  | 		// uncomment this if you want set timer on startup
  | 		setTrigger(defaultTrigger);
  | 	}
  | 
  | 	public void restoreDefault()
  | 	{
  | 		setTrigger(defaultTrigger);
  | 	}
  | 
  | 	public void setTrigger(String trigger)
  | 	{
  | 		try
  | 		{
  | 			QuartzTriggerHandle handle = QuartzDispatcher.instance().scheduleTimedEvent("someEvent", new CronSchedule((Long) null, trigger));
  | 
  | 			if (this.handle != null)
  | 	            this.handle.cancel();
  | 
  | 			this.handle = handle;
  | 			this.trigger = trigger;
  | 		}
  | 		catch (Exception e)
  | 		{
  | 			log.error("Erro configurando timer: #0", e, trigger);
  | 		}
  | 	}
  | 
  | 	public String getTrigger()
  | 	{
  | 		return trigger;
  | 	}
  | 
  | 	public void cancel()
  | 	{
  | 		try
  | 		{
  | 			if (handle != null)
  | 	            handle.cancel();
  | 			handle = null;
  | 			trigger = null;
  | 		}
  | 		catch (Exception e)
  | 		{
  | 			log.error("Erro configurando timer: #0", e, trigger);
  | 		}
  | 	}
  | 
  | 	@Destroy
  | 	public void stop()
  | 	{
  | 		cancel();
  | 	}
  | 
  | }
  | 

Thanks,

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119580#4119580

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119580



More information about the jboss-user mailing list