Where The Streets Have No Name

Quartz Job Control code 본문

Developement/Java

Quartz Job Control code

highheat 2006. 12. 4. 16:37
<%@ page contentType="text/html;charset=euc-kr"  %>
<%@ page import="org.quartz.*" %>
<%@ page import="org.quartz.impl.StdSchedulerFactory" %>
<%@ page import="org.quartz.ee.servlet.*" %>
<%@ page import="lgmsales.mailing.job.*" %>
<%
String[] jobGroups;
String[] jobsInGroup;
int i;
int j;
ServletContext ctx = request.getSession().getServletContext();
Scheduler scheduler = null;
StdSchedulerFactory factory = (StdSchedulerFactory)ctx.getAttribute(QuartzInitializerServlet.QUARTZ_FACTORY_KEY);
scheduler = factory.getScheduler();
   
//scheduler.pauseJob("testjob2", "testgroup"); //정지

//scheduler.resumeJob("testjob2", "testgroup"); //재시작


//수정
/*
CronTrigger cronTrigger = new CronTrigger("testtrigger2","testgroup");
cronTrigger.setJobName("testjob2");
cronTrigger.setJobGroup("testgroup");
cronTrigger.setCronExpression("2 * * ? * MON-FRI");
scheduler.rescheduleJob("testtrigger2", "testgroup",cronTrigger);
*/


scheduler.deleteJob("testjob2", "testgroup"); //삭제

//추가
JobDetail jd = new JobDetail("testjob2", "testgroup",TestJob2.class);
CronTrigger cronTrigger = new CronTrigger("testtrigger2","testgroup");
cronTrigger.setCronExpression("10 * * ? * MON-FRI");
scheduler.scheduleJob(jd, cronTrigger);
   
jobGroups = scheduler.getJobGroupNames();
for (i = 0; i < jobGroups.length; i++) {
   out.println("Group: " + jobGroups[i] + " contains the following jobs : ");
   jobsInGroup = scheduler.getJobNames(jobGroups[i]);
   for (j = 0; j < jobsInGroup.length; j++) {
      out.println("- " + jobsInGroup[j]);
   }
   out.println("<br>");
}
%>