spring quartz 타이머 동적 설정 실행 시간

2196 단어 springquartz타이머
1. 타이머 설정 파일 내용

	<bean id="testServiceImpl"
		class="com.biz.impl.TestServiceImpl"
		singleton="true">
		<property name="cacheService" ref="exchangeCacheService" />
	</bean>
<bean id="schedulerJobDetail"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="testServiceImpl" />
		<property name="targetMethod" value="run" />
		<property name="concurrent" value="false" />
	</bean>
	<bean id="cronTrigger"
		class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="schedulerJobDetail" />
		<property name="cronExpression">
			<value>0 0/1 * * * ?</value>
		</property>
	</bean>
	<bean id="schedulerFactory"
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref local="cronTrigger" />
			</list>
		</property>
	</bean>



<bean id="testService"
		class="com.biz.impl.Test1ServiceImpl">
		<property name="scheduler" ref="schedulerFactory"/> 
	</bean>

2. 타이머 시간 간격 클래스 의 코드 수정

public void updateNotificationInterval() throws SchedulerException,
			ParseException {

		//            scheduler  trigger
		CronTriggerBean trigger = (CronTriggerBean) scheduler.getTrigger(
				"cronTrigger", Scheduler.DEFAULT_GROUP);

		String originConExpression = trigger.getCronExpression();
		//               2      
		trigger.setCronExpression("0 0/2 * * * ?");
		scheduler.rescheduleJob("cronTrigger", Scheduler.DEFAULT_GROUP, trigger);

	}

좋은 웹페이지 즐겨찾기