2014-07-08 2 views
0

현재 우리는 애플리케이션에서 쿼츠 타이머를 사용하여 매일 자정에 메소드를 실행합니다. 문제는 여러 대의 서버에 배포 할 것이므로 각 서버가 작동하지 않도록하는 것입니다. 우리는 한 대의 서버로 작업을 시작하기를 원합니다.단일 호스트에서 쿼츠 작업을 실행하는 방법

JMX를 통해 노출되므로 호스트 중 하나에서 쿼츠 타이머를 일시 중지/종료 할 수 있지만 원하는 해결책은 아닙니다.

코드를 통해 쿼츠 작업을 하나의 호스트에서만 실행하도록 설정할 수 있습니까? (: 부동산-자리 ... 컨텍스트)에

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util-3.2.xsd"> 

<bean id="timerJob" 
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
<property name="targetObject" value="com.x.y.TestClass" /> 
<property name="targetMethod" value="testMethod" /> 
</bean> 

<!-- Cron Trigger, runs every day at 2 AM --> 
<bean id="cronTrigger" 
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
<property name="jobDetail" ref="timerJob" /> 
<property name="cronExpression" value="$timer.chronExpression}" /> 

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
<property name="jobDetails"> 
    <list> 
    <ref bean="timerJob" /> 
    </list> 
</property> 
<property name="triggers"> 
    <list> 
    <ref bean="cronTrigger" /> 
    </list> 
</property> 
<property name="quartzProperties"> 
    <util:properties> 
    <prop key="org.quartz.scheduler.jmx.export">false</prop> 
    <prop key="org.quartz.scheduler.jmx.objectName"> 
     quartz:type=QuartzScheduler,name=TestClass 
    </prop> 
    </util:properties> 
</property> 
</bean> 
</beans> 

답변

0

당신은의 SchedulerFactoryBean과 봄 PropertyPlaceholderConfigurer와의 autoStartup 속성을 사용할 수 있습니다 - 아래

우리가 사용하는 XML이다 JVM 시스템 프로퍼티 또는 클래스 패스상의 표준 자바 프로퍼티 파일로부터 플래그 값을 얻는다.

<bean id="scheduler" 
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    ... 
    <property name="autoStartup" value="${quartz.started}"/> 
... 
</bean> 
,210

또는, 당신은 사용할 수 있습니다 : 그들은 모두 단지 호스트에서 실행되는 것처럼

<property name="autoStartup" ref="custom_factory_bean_that_reads_the_flag_from_app_cfg"/> 

이 분명히 모든 작업에 영향을 미칠 경우 autoStartup = 사실.

AFAIK Quartz API 자체는 특정 작업의 실행을 특정 호스트로 제한 할 수 없습니다.

0

해당 컴퓨터에 대해서만 스케줄러를 정의 할 수 있습니다. 스케줄러는 작업 스케줄링을 담당합니다.

관련 문제