quartz 정시 작업에서의 응용
1. 마븐의pom.xml 파일에quartz 패키지 의존 추가
그리고 mvn install, 해당 패키지 다운로드
2.src/main/resouces 아래에quartz를 추가합니다.properties 파일입니다.
프로필의 상세한 설정은 말할 것도 없고, 특히 프로필에 작업에 대한 지속성을 추가했다
지원:
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=XXX
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.clusterCheckinInterval=15000
3. 스프링 프로필에 작업 bean.
우선quartz가 정해진 임무를 수행하는 방식을 말씀드리겠습니다.quartz가 사용자에게 노출된 역할은 대략 세 가지가 있는데 그것이 바로 Scheduler, Trigger,Task이다.
Task는 바로 실현할 작업입니다. 사용자 정의task는QuartzJobBean 인터페이스를 실현해야 합니다.Trigger는 트리거로서 특정한 트리거 조건을 제정하여task를 트리거한다.Scheduler는 트리거와 작업을 연결하는 스케줄러입니다.물론 Trigger 자체에도 Job 매개변수가 있을 수 있습니다.또한 Scheduler는 런타임 시 task를 동적으로 스케줄링할 수 있습니다.
다음은 내가 구성한 스케줄링입니다.
<bean id="a" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>
com.××
</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="c">
<ref bean="C" />
</entry>
</map>
</property>
</bean>
<bean id="b"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="a" />
</property>
<property name="startDelay">
<value>9100</value>
</property>
<property name="repeatInterval">
<value>9100</value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties"/>
<property name="startupDelay" value="30"/>
<property name="triggers">
<list>
<ref local="b" />
</list>
</property>
</bean>
이렇게 하면 임무에 자신의 업무 코드만 쓰면 된다.
그리고 이런 식으로 여러 개의 scheduler를 설정하는 경우quartz에서properties가 스레드 탱크를 설정했습니다
org.quartz.threadPool.threadCount = 8, 모든 scheduler는 8개의 단독 라인으로 작업을 실행할 수 있습니다.
그러나 현재 프로젝트에서 동기화를 고려하여 매번 이 job를 실행하는 라인만 있기를 바랍니다.그래서 모든 Job은 StatefulJob 인터페이스를 실현하고,
이 인터페이스의 의미는 다음과 같습니다.
/**
* <p>
* A marker interface for <code>{@link org.quartz.JobDetail}</code> s that
* wish to have their state maintained between executions.
* </p>
*
* <p>
* <code>StatefulJob</code> instances follow slightly different rules from
* regular <code>Job</code> instances. The key difference is that their
* associated <code>{@link JobDataMap}</code> is re-persisted after every
* execution of the job, thus preserving state for the next execution. The
* other difference is that stateful jobs are not allowed to execute
* concurrently, which means new triggers that occur before the completion of
* the <code>execute(xx)</code> method will be delayed.
대체로 두 가지 작용만 있다.
1. Job의 실행 과정에서 JobDataMap의 대상의 상태를 유지하여 그 안의 대상이 매번 실행된 후에 미리 지속되도록 한다.
다음 실행 사용
2. 여러 개의 라인이 한꺼번에 어떤 job을 실행하는 것을 방지합니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
thymeleaf로 HTML 페이지를 동적으로 만듭니다 (spring + gradle)지난번에는 에서 화면에 HTML을 표시했습니다. 이번에는 화면을 동적으로 움직여보고 싶기 때문에 입력한 문자를 화면에 표시시키고 싶습니다. 초보자의 비망록이므로 이상한 점 등 있으면 지적 받을 수 있으면 기쁩니다! ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.