[jboss-user] [JBoss Seam] - Re: Starting up Asynchronous Method at startup

ASavitsky do-not-reply at jboss.com
Tue Oct 16 16:33:48 EDT 2007


Here's what works for me (no EJB3 - plain POJO, Quartz and Tomcat, all deployed as WAR):

@Name ("scheduler")
  | @Scope (ScopeType.APPLICATION)
  | @Startup
  | public class Scheduler {
  | 	@In
  | 	private IService service;
  | 	@Logger
  | 	private Log log;
  | 	// set in seam.properties via scheduler.reminderCron
  | 	private String reminderCron;
  | 
  | 	public void setReminderCron(String reminderCron) {
  | 		this.reminderCron = reminderCron;
  | 	}
  | 	@Create
  | 	public void startJobs() {
  | 		log.info("Reminder task started on #0, cron schedule is #1",
  | 				new Date(), reminderCron);
  | 		service.sendReminders(reminderCron);
  | 	}
  | }

public interface IService extends Serializable {
  | 	void sendReminders(String cron); // other methods are omitted
  | }

@Name ("service")
  | @Scope (ScopeType.CONVERSATION)
  | @AutoCreate
  | @Transactional
  | public class Service implements IService {
  | 	@Asynchronous
  | 	public void sendReminders(@IntervalCron String cron) {
  | 		log.info("Reminder task activated on #0", new Date());
  | 		// plus whatever other functionality you need here...
  | 	}
  | }
  | 

The scheduler starts with the app, and runs every morning (as per cron expression, which you can change as needed)

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

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



More information about the jboss-user mailing list