0

I'm needing to make a service that schedules jobs that are basically get requests that hit some servlet. I tried to do this w/ a servlet context listener based on this post, Running a background Java program in Tomcat, but the web.xml changes that were defined are causing 404 errors on the Tomcat server. Does anyone have any other suggestions on how to accomplish this?

One idea I have at this point is to define a runnable servlet

public class Service extends HttpServlet implements Runnable    {
     //Does stuff
     init()  {
         new Thread(this);
     }
}

Is this a reasonable approach?

Community
  • 1
  • 1
Andy McCall
  • 446
  • 1
  • 4
  • 15

1 Answers1

0

you can look into using quartz scheduler for jobs :

http://quartz-scheduler.org/

for instance (not specific to your task):

import java.util.Map;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class SchedulerJob implements Job
{
  public void execute(JobExecutionContext context)
  throws JobExecutionException {

    Map dataMap = context.getJobDetail().getJobDataMap();
    SchedulerTask task = (SchedulerTask)dataMap.get("schedulerTask");
    task.printSchedulerMessage();
  }
}

Another option (for a quick turaround) would be to just use a cron job or windows task manager depending on your OS.

ali haider
  • 19,175
  • 17
  • 80
  • 149