Java tutorial
/* * Copyright 2006-2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package lcn.module.batch.core.launch.support; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author * @since 2012. 07.25 * @version 1.0 * @see <pre> * ?(Modification Information) * * ? ? * ------- -------- --------------------------- * 2012. 07.25 ? * </pre> */ public class SchedulerRunner { // Logger protected static final Log logger = LogFactory.getLog(SchedulerRunner.class); // Job Context ? XML ? private String contextPath; // Scheduler ? ? XML ? private String schedulerJobPath; // Job? ? XML ? private List<String> jobPaths; // Scheduling? private long delayTime; /** * SchedulerRunner ?? * * @param contextPath : Job Context ? XML ? * @param schedulerJobPath : Scheduler ? ? XML ? * @param jobPaths : Job? ? XML ? * @param delayTime : Scheduling? */ public SchedulerRunner(String contextPath, String schedulerJobPath, List<String> jobPaths, long delayTime) { this.contextPath = contextPath; this.schedulerJobPath = schedulerJobPath; this.jobPaths = jobPaths; this.delayTime = delayTime; } /** * contextPath . * @param contextPath */ public void setContextPath(String contextPath) { this.contextPath = contextPath; } /** * schedulerJobPath . * @param schedulerJobPath */ public void setSchedulerJobPath(String schedulerJobPath) { this.schedulerJobPath = schedulerJobPath; } /** * jobPaths . * @param jobPaths */ public void setJobPath(List<String> jobPaths) { this.jobPaths = jobPaths; } /** * delayTime . * @param delayTime */ public void setDelayTime(long delayTime) { this.delayTime = delayTime; } /** * Scheduler . * * Thread.sleep()? ?, Scheduler schedulerJob? * ApplicationContext ?? delayTime ? . * ApplicationContext ? ? Scheduler Batch Job? . * : 10 Batch Job (Cron ?: 0/10 * * * * ?) * ?? xml? : /framework/batch/batch-scheduler-runner-context.xml */ public void start() { List<String> paths = new ArrayList<String>(); paths.add(contextPath); paths.add(schedulerJobPath); // XML ?? ContextPath? ?. for (int index = 0; index < jobPaths.size(); index++) { paths.add(jobPaths.get(index)); } String[] locations = paths.toArray(new String[paths.size()]); // ApplicationContext ?. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(locations, false); context.refresh(); logger.warn("ApplicationContext Running Time: " + delayTime / 1000 + " seconds"); logger.warn("CronTrigger is loaded on Spring ApplicationContext"); try { // ? , ?? Scheduler ?. Thread.sleep(delayTime); } catch (InterruptedException e) { /* interrupted by other thread */ } context.close(); } }