---
title: "spring quartz 线程调度服务"
author: "solomon"
date: "2010-12-24T10:38:17Z"
tags: []
categories: ["非技术"]
slug: "spring-quartz"
draft: false
lastmod: "2010-12-24T10:38:17Z"
id: 850903
url: "https://solomon.iteye.com/blog/850903"
---

&lt;!-- spring 线程调度注册,  注册执行的任务 class 和 被执行的 service --&gt;  
    &lt;bean id="deptSyncJob" class="org.springframework.scheduling.quartz.JobDetailBean"&gt;  
        &lt;property name="jobClass"&gt;  
           &lt;value&gt;com.openid.rst.server.quartz.DepartmentSyncJob&lt;/value&gt;  
        &lt;/property&gt;  
        &lt;property name="jobDataAsMap"&gt;  
          &lt;map&gt;  
           &lt;entry key="someService"&gt;  
             &lt;ref bean="someService"/&gt;  
           &lt;/entry&gt;  
         &lt;/map&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;

 

    &lt;!--

      /\** 实现的线程执行类  \*/

       package com.openid.rst.server.quartz;

       import org.quartz.JobExecutionContext;  
       import org.quartz.JobExecutionException;  
       import com.openid.rst.service.SecurityService;  
       import org.springframework.scheduling.quartz.QuartzJobBean;

 

      public class DepartmentSyncJob extends QuartzJobBean {

   
       public SecurityService getSecurityService() {  
          return this.securityService;  
       }

 

       public void setSecurityService(SecurityService securityService) {  
          this.securityService = securityService;  
       }

 

       private SecurityService securityService;  
   

       protected void executeInternal(JobExecutionContext context)  
           throws JobExecutionException {  
        securityService.doDeptSyncFromIddbuser();  
       }

   }

       --&gt;  
   

  

    &lt;!-- spring 配置线程调用及参数 --&gt;  
    &lt;bean id="simpleReportTrigger"                     class="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;  
       &lt;property name="jobDetail"&gt;  
            &lt;ref bean="deptSyncJob"/&gt;  
       &lt;/property&gt;  
        
       &lt;!--  
       &lt;property name="startDelay"&gt;    
            &lt;value&gt;1800000-nouse &lt;/value&gt;  
       &lt;/property&gt;  
      --&gt;  
       
       &lt;property name="startDelay"&gt;  
            &lt;value&gt;12000&lt;/value&gt;  
       &lt;/property&gt;  
        
       &lt;property name="repeatInterval"&gt;  
            &lt;value&gt;86400000&lt;/value&gt;  
       &lt;/property&gt;

    &lt;/bean&gt;

 

   

   &lt;!-- 线程执行工厂 --&gt;

    &lt;bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;  
       &lt;property name="triggers"&gt;  
          &lt;list&gt;  
            &lt;ref bean="simpleReportTrigger"/&gt;  
          &lt;/list&gt;  
       &lt;/property&gt;  
    &lt;/bean&gt;