ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Job Scheduling in Java
Subject:   Integrating quartz in a web application
Date:   2006-11-08 05:11:44
From:   shivapaka
Response to: Integrating quartz in a web application

This is the servlet file u have to call


package com.v2sol;


import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.CronTrigger;
import org.quartz.impl.StdSchedulerFactory;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.HttpServlet;
import org.quartz.ee.servlet.*;


public class ExcelDBServlet extends HttpServlet {


@Override
public void init(ServletConfig config) throws ServletException {

System.out.println("Initializing Scheduler PlugIn for Jobs!");
super.init(config);
ServletContext ctx = config.getServletContext();
Scheduler scheduler = null;
StdSchedulerFactory factory = (StdSchedulerFactory)
ctx.getAttribute(QuartzInitializerServlet.QUARTZ_FACTORY_KEY);

try {
scheduler = factory.getScheduler();
JobDetail jd = new JobDetail("job1", "group1",ExcelJob.class);
CronTrigger cronTrigger = new CronTrigger("trigger1","group1");
String cronExpr = null;
cronExpr = getInitParameter("cronExpr");
System.out.println(cronExpr);
cronTrigger.setCronExpression(cronExpr);
scheduler.scheduleJob(jd, cronTrigger);
System.out.println("Job scheduled now ..");

} catch (Exception e){
e.printStackTrace();
}
}

@Override
public void service(ServletRequest request, ServletResponse response)throws ServletException, IOException {
PrintWriter pw=response.getWriter();
pw.print("<html> <body> <h1>");
pw.print("Please wait,DataBase Operations is performing.............");
pw.print("</h1></body></html>");
}
@Override
public String getServletInfo() {
return null;
}
}



-----
web.xml



<web-app>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<display-name>Quartz Initializer Servlet</display-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>


<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>

</servlet>

<servlet>
<servlet-name>first</servlet-name>
<servlet-class>com.v2sol.StartQuartz</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>first</servlet-name>
<url-pattern>/fst</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>one</servlet-name>
<servlet-class>com.v2sol.ExcelDBServlet</servlet-class>
<init-param>
*******<param-name>cronExpr</param-name>
<param-value>0,30 * * ? * MON-FRI</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/excel</url-pattern>
</servlet-mapping>


</web-app>




1 to 5 of 5
  1. Integrating quartz in a web application
    2007-05-28 23:52:17  Saravjava [View]

  2. Integrating quartz in a web application
    2007-03-27 06:35:11  screenforsathish [View]

  3. Integrating quartz in a web application
    2007-03-27 06:35:11  screenforsathish [View]

  4. Integrating quartz in a web application
    2007-03-27 06:35:10  screenforsathish [View]

  5. Integrating quartz in a web application
    2007-03-27 06:35:09  screenforsathish [View]

1 to 5 of 5