JAVA] Quartz (쿼츠)를 사용하여 자바 스케줄링(scheduling) 하기
2018.02.08 10:57
JAVA] Quartz (쿼츠)를 사용하여 자바 스케줄링(scheduling) 하기
Quartz : http://www.opensymphony.com/
tutorial : http://quartz-scheduler.org/docs/tutorial/index.html
추가 Library
- Apache Commons Collections >> http://commons.apache.org/collections/
- Apache Commons Logging >> http://commons.apache.org/logging/
- Apache Log4j >> http://logging.apache.org/log4j/1.2/index.html
참고 : http://blog.naver.com/kst7132?Redirect=Log&logNo=140101991602
http://blog.naver.com/minis24?Redirect=Log&logNo=80105633208
스트러츠에서 Quartz 사용 : http://mygeni.tistory.com/79
스프링에서 Quartz 사용 : http://suya55.springnote.com/pages/1126992
CronTrigger 사용한 예제
|
먼저 테스트로 사용할 Job 클래스 두개를 아래와 같이 만들어 준다.
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
public class TestJob1 implements Job {
public void execute(JobExecutionContext context) {
System.out.println("TestJob1.execute() is Executed... : " + new Date());
}
}
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
public class TestJob2 implements Job {
public void execute(JobExecutionContext context) {
System.out.println("TestJob2.execute() is Executed... : " + new Date());
}
}
TestJob1.execute() is Executed... : Tue Jun 16 19:09:00 KST 2009
TestJob2.execute() is Executed... : Tue Jun 16 19:09:30 KST 2009 TestJob1.execute() is Executed... : Tue Jun 16 19:10:00 KST 2009 TestJob2.execute() is Executed... : Tue Jun 16 19:10:30 KST 2009 TestJob1.execute() is Executed... : Tue Jun 16 19:11:00 KST 2009
1. Seconds (0-59) - * / 2. Minutes (0-59) - * / 3. Hours (0-23) - * / 4. Day-of-month (1-31) - * ? / L W C 5. Month (1-12 or JAN-DEC) - * / 6. Day-of-week (1-7 or SUN-SAT) - * ? / L C # 7. Year (optional, empty, 1970-2099) - * /
|
SimpleTrigger을 사용한 예제
|
[ex : Job 구현 클래스]
[ex : 잡스케줄링]
|
추가로... J2EE환경에서 작동하게 하려면 다음과 같이 설정할 수 있다.
J2EE환경에서는 servlet으로 초기화 하는 부분을 작성하고 WAS시작시 해당 servlet을 호출하도록 설정(web.xml에서 설정)하면 서비스가 시작 되면서 스케쥴이 동작하게된다.
SimpleTrigger을 사용한 예제
|
[ex : Job 구현 클래스]
[servlet으로 스케쥴 작성]
|
출처: http://invincure.tistory.com/entry/Java-Quartz-쿼츠를-사용하여-자바-스케줄링scheduling-하기 [Do you want it? Come get it.]
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.

