블로그 이미지
yukino

카테고리

분류 전체보기 (56)
내이야기 (11)
좋아하는이야기 (17)
책이야기 (1)
건강정보 (3)
개발이야기 (19)
Hustle Doo (5)
Total
Today
Yesterday

'Quartz'에 해당되는 글 1건

  1. 2007.11.14 springframework에서 quartz 사용하기

1. 관련 config 파일을 생성하여 quartz를 사용하기 위한 값을 설정한다.
(혹은 spring에서 사용하는 applicationContext에 설정)

2. 설정 내용

<beans>
 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
   <list>
    <ref bean="cronStatisticsTrigger"/>
   </list>
  </property>
 </bean>
 <bean id="cronStatisticsTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
  <property name="jobDetail">
      <ref bean="exampleJob" />
     </property>
  <property name="cronExpression">
      <value>0 0/5 * * * ?</value>
     </property>
    </bean>
 <bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass">
   <value>com.hs.calendar.todo.ExampleJob</value>
  </property>
  <property name="jobDataAsMap">
   <map>
    <entry key="timeout"><value>5</value></entry>
   </map>
  </property>
 </bean>

</beans>

3. 소스 개발
package com.hs.calendar.todo;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

public class ExampleJob extends QuartzJobBean {
 static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ExampleJob.class);
 
 private int timeout =0;
 
 public void setTimeout(int timeout) {
  this.timeout = timeout;
 }
 
 protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
  // 작업 프로세스 정의
  Date date = new Date();
  System.out.print("[ExampleJob] Now is " + date.toString());
 
  if (logger.isDebugEnabled()) {
   logger.debug("[ExampleJob.executeInternal] START");
   logger.debug("[ExampleJob.executeInternal] dddd");
   logger.debug("[ExampleJob.executeInternal] END");
  }
 }
}

Posted by yukino
, |