Wow, u guys r super. So many help.

I will go with Daniel's solution. To maximize portability, I think the best
solution is
not to depend on DB timestamp to delete it as different DB will have
different
ways of doing it, hence learning new things if change new DB.

Thanks guys.
:D

----- Original Message ----- 
From: "Daniel Perry" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, August 20, 2004 5:15 AM
Subject: RE: Help on Action implementing thread for checking user
registration thru email?


> I previously posted a message on how i did this as a struts plugin, so
i've
> reposted below.
>
> To do what you require, instead of scheduling a job for each entry after
> 24hrs, i would include a timestamp in the database, then say every hour,
> check for expired entries and delete them.
>
> ----------------------------
> Nope, you dont need to start another process - i use a struts plugin to
load
> and initialise Quartz.  It will run in other threads, but this will all be
> done for you behind the scenes.
>
> The code for my struts plugin is below (if it's of any help).  Add the
> following entry to the struts-config-default.xml in the plug-in section to
> load it:
>
> <plug-in className="com.netcase.pdp.service.SchedulerService"></plug-in>
>
> It runs a "Job" every 30 mins.
>
> This job takes the form:
>
> public class RemoveOldProvisionalTrainingJob implements StatefulJob {
> public void execute(JobExecutionContext arg0) throws JobExecutionException
{
> // code to do actual work here
> }
> }
>
>
> Note that i'm implementing StatfulJob - this stops it running two of the
> same job at the same time.
>
> Daniel.
>
>
> ---------------------SchedulerService.java-------------------------
> package com.netcase.pdp.service;
>
> import java.util.Date;
>
> import javax.servlet.ServletException;
>
> import org.apache.struts.action.ActionServlet;
> import org.apache.struts.action.PlugIn;
> import org.apache.struts.config.ModuleConfig;
> import org.quartz.JobDetail;
> import org.quartz.Scheduler;
> import org.quartz.SchedulerException;
> import org.quartz.SchedulerFactory;
> import org.quartz.SimpleTrigger;
>
> import
> com.netcase.pdp.service.scheduledjobs.RemoveOldProvisionalTrainingJob;
>
> /**
>  * @author Daniel Perry
>  *
>  */
> public class SchedulerService implements PlugIn {
>
> Scheduler sched;
>
> public void init(ActionServlet servlet, ModuleConfig moduleConf)
> throws ServletException {
> System.out.println("Starting scheduler service...");
>
> SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
> try {
> sched = schedFact.getScheduler();
> sched.start();
>
> JobDetail jobDetail = new JobDetail(
> "removeOldProvisionalTrainingJob",
> Scheduler.DEFAULT_GROUP,
> RemoveOldProvisionalTrainingJob.class);
>
> // new trigger - repeat every 30 mins starting in 5 mins time
> // (delay for startup)
> SimpleTrigger trigger = new SimpleTrigger("30MinTrigger",
> Scheduler.DEFAULT_GROUP, new Date(new Date().getTime()
> + (5L* 60L * 1000L)), null,
> SimpleTrigger.REPEAT_INDEFINITELY, 30 * 60L * 1000L);
>
> sched.scheduleJob(jobDetail, trigger);
>
>
> } catch (SchedulerException ex) {
> ex.printStackTrace();
> }
>
> }
>
> public void destroy() {
> try {
> sched.shutdown();
> } catch (SchedulerException ex) {
> ex.printStackTrace();
> }
> sched = null;
> }
>
> }
> -------------------------------------------------------------------
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to