欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用spring整合Quartz實現(xiàn)—定時器功能

 更新時間:2018年04月25日 14:14:53   作者:愿你所到之處遍地陽光  
這篇文章主要介紹了使用spring整合Quartz實現(xiàn)—定時器功能,不基于特定的基類的方法,需要的朋友可以參考下

使用spring整合Quartz實現(xiàn)—定時器(Maven項目做演示)

不基于特定的基類的方法

一,開發(fā)環(huán)境以及依賴的jar包

    Spring 4.2.6.RELEASE

    Maven 3.3.9

    Jdk 1.7

    Idea 15.04

二,不可少的jar依賴(添加在maven項目里面的pom.xml文件里面)

 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-context-support</artifactId>
 <version>4.2.6.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.quartz-scheduler</groupId>
 <artifactId>quartz</artifactId>
 <version>2.2.1</version>
 </dependency>

三,實現(xiàn)定時器時使用到的文件:

     planWorkExcute.java    --定時器執(zhí)行的類

     spring-plan.xml    --配置定時器信息的xml

四,實現(xiàn)定時器步驟:

   1,創(chuàng)建 planWorkExcute.java文件  ,在   cc.royao.plantask   包下。      

package cc.royao.plantask;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;//可以刪除
import org.springframework.beans.factory.annotation.Autowired;
public class PlanWorkExecute {
 Logger logger = Logger.getLogger(this.getClass());//logger打印日志,可以去掉
 /**
 * 定時器執(zhí)行的方法
 */
 public synchronized void withdrawNoAuditTask() {
 SimpleDateFormat outFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
 System.out.println("開始提現(xiàn)免審核任務-------------------------------" + outFormat.format(new Date()));
 logger.info("開始提現(xiàn)免審核任務-------------------------------");
 System.out.println("結束提現(xiàn)免審核任務-------------------------------" + outFormat.format(new Date()));
 logger.info("結束提現(xiàn)免審核任務-------------------------------");
 }
}

  2,創(chuàng)建spring-plan.xml  配置文件  注:創(chuàng)建一個定時器的配置文件就行,如果需要多個定時器,直接在spring-plan.xml添加 bean和定義定時器類的方法就行,不需要創(chuàng)建多個xml,

      · 關于那個定時器多久執(zhí)行的   Cron表達式 可以參考:http://www.dbjr.com.cn/article/138900.htm

      ·有在線生成表達式的網(wǎng)址:http://cron.qqe2.com/

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-lazy-init="false">
<bean id="job1" class="cc.royao.plantask.PlanWorkExecute" /><!-- 修改為你的定時類的路徑 -->
<!-- 可以創(chuàng)建多個定時bean -->
<bean id="jobDetail_1"
 class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
 <property name="targetObject">
 <ref bean="job1" /> 
 </property>
 <property name="targetMethod">
 <value>withdrawNoAuditTask</value><!-- 定時器類的方法名-->
 </property>
</bean>
<bean id="cronTrigger_1"
 class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
 <property name="jobDetail">
 <ref bean="jobDetail_1" /> <!-- 這里對應上面bean-->
 </property>
 <property name="cronExpression">
 <value>0/2 * * * * ?</value><!-- 0 10 0 * * ? 每天0:10執(zhí)行 -->
 </property>
</bean>
<bean
 class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
 <property name="triggers">
 <list>
 <ref local="cronTrigger_1" /> <!-- 每加一個定時器這里也要加-->
 </list>
 </property>
</bean>
</beans>

  3,需要在  applicationContext.xml 中引入  spring-plan.xml    以下代碼重點在最下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jee="http://www.springframework.org/schema/jee"
 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:cache="http://www.springframework.org/schema/cache"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd"
 default-lazy-init="true">
 <!-- 加載系統(tǒng)properties文件配置 -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 <property name="locations">
  <list>
  <value>WEB-INF/jdbc.properties</value>
  <!-- <value>WEB-INF/sms.properties</value> -->
  </list>
 </property>
 </bean>
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
 <property name="driverClassName">
  <value>${jdbc.driverClass}</value>
 </property>
 <!--<property name="defaultAutoCommit" value="false"/>-->
 <property name="url">
  <value>jdbc:mysql://192.168.14.239:3306/test?useUnicode=true&amp;characterEncoding=utf-8</value>
 </property>
 <property name="username">
  <value>${jdbc.username}</value>
 </property>
 <property name="password">
  <value>${jdbc.password}</value>
 </property>
 <property name="maxActive">
  <value>20</value>
 </property>
 <property name="maxIdle">
  <value>60</value>
 </property>
 <property name="maxWait">
  <value>20000</value>
  <!-- 0 -->
 </property>
 <property name="removeAbandoned">
  <value>true</value>
 </property>
 <property name="removeAbandonedTimeout">
  <value>6000000</value>
  <!-- 180 -->
 </property>
 <!-- add -->
 <property name="validationQuery" value="SELECT 1"></property>
 <property name="testWhileIdle" value="true"></property>
 <property name="testOnBorrow" value="true"></property>
 <property name="timeBetweenEvictionRunsMillis" value="3600000"></property>
 <property name="numTestsPerEvictionRun" value="50"></property>
 <property name="minEvictableIdleTimeMillis" value="120000"></property>
 <!-- add -->
 </bean>
 <!-- SqlSessionFactory -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
 <property name="dataSource" ref="dataSource"/>
 </bean>
 <bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
 <property name="corePoolSize" value="1"/>
 <property name="maxPoolSize" value="10"/>
 <property name="keepAliveSeconds" value="300"/>
 <property name="queueCapacity" value="50"/>
 <property name="WaitForTasksToCompleteOnShutdown" value="true"/>
 </bean>
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="dataSource"></property>
 </bean>
 <!--&lt;!&ndash; 自動掃描service實現(xiàn) &ndash;&gt;-->
 <!--<context:component-scan base-package="com.royao">-->
 <!--<context:include-filter type="regex"-->
 <!--expression="com.royao.services.*" />-->
 <!--</context:component-scan>-->
 <aop:config proxy-target-class="true">
 <aop:pointcut id="serviceOperation" expression="execution(* cc.royao.mana.auth.service.*.impl.*ServiceImpl.*(..))"/>
 <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
 </aop:config>
 <!-- 配置事務通知 -->
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
 <tx:attributes>
  <tx:method name="*" rollback-for="Exception"/>
 </tx:attributes>
 </tx:advice>
 <tx:advice id="transactionManagerAdivice" transaction-manager="transactionManager">
 <tx:attributes>
  <tx:method name="*insert*" propagation="REQUIRED"/>
  <tx:method name="*add*" propagation="REQUIRED"/>
  <tx:method name="*update*" propagation="REQUIRED"/>
  <tx:method name="*Update*" propagation="REQUIRED"/>
  <tx:method name="*del*" propagation="REQUIRED"/>
  <tx:method name="*create*" propagation="REQUIRED"/>
  <tx:method name="doApproved" propagation="REQUIRED"/>
  <tx:method name="batchDelFm" propagation="REQUIRED"/>
  <tx:method name="editTemplate" propagation="REQUIRED"/>
  <tx:method name="dummyDelete" propagation="REQUIRED"/>
  <tx:method name="batchDelUser" propagation="REQUIRED"/>
  <!--<tx:method name="*" propagation="REQUIRED"/>-->
 </tx:attributes>
 </tx:advice>
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
 <property name="basePackage">
  <value>cc.royao.mana.auth.mapper.*</value>
 </property>
 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
 </bean>
 <import resource="application-servlet.xml"/>
  <!-- 重點在這里 ,我把整個xml文件內(nèi)容復制出來,怕你們不知道插入在哪里-->
 <import resource="spring-plan.xml"/>
</beans>

總結

以上所述是小編給大家介紹的使用spring整合Quartz實現(xiàn)—定時器功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • Java實現(xiàn)文件的分割與合并

    Java實現(xiàn)文件的分割與合并

    這篇文章主要為大家詳細介紹了Java實現(xiàn)文件的分割與合并,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Java程序執(zhí)行的全流程

    Java程序執(zhí)行的全流程

    這篇文章主要介紹了Java程序執(zhí)行的全流程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Java實例講解多態(tài)數(shù)組的使用

    Java實例講解多態(tài)數(shù)組的使用

    本文章向大家介紹Java多態(tài)數(shù)組,主要包括Java多態(tài)數(shù)組使用實例、基本知識點總結和需要注意事項,具有一定的參考價值,需要的朋友可以參考一下
    2022-05-05
  • postman中實現(xiàn)傳遞@RequestBody參數(shù)

    postman中實現(xiàn)傳遞@RequestBody參數(shù)

    這篇文章主要介紹了postman中實現(xiàn)傳遞@RequestBody參數(shù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java Synchronize下的volatile關鍵字詳解

    Java Synchronize下的volatile關鍵字詳解

    這篇文章主要介紹了Java Synchronize下的volatile關鍵字詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • Spring Boot應用監(jiān)控的實戰(zhàn)教程

    Spring Boot應用監(jiān)控的實戰(zhàn)教程

    Spring Boot 提供運行時的應用監(jiān)控和管理功能,下面這篇文章主要給大家介紹了關于Spring Boot應用監(jiān)控的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧
    2018-05-05
  • SpringBoot+Mybatis項目使用Redis做Mybatis的二級緩存的方法

    SpringBoot+Mybatis項目使用Redis做Mybatis的二級緩存的方法

    本篇文章主要介紹了SpringBoot+Mybatis項目使用Redis做Mybatis的二級緩存的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Java 實戰(zhàn)項目錘煉之在線蛋糕商城系統(tǒng)的實現(xiàn)

    Java 實戰(zhàn)項目錘煉之在線蛋糕商城系統(tǒng)的實現(xiàn)

    讀萬卷書不如行萬里路,只學書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+jsp+jdbc+mysql實現(xiàn)一個在線蛋糕商城系統(tǒng),大家可以在過程中查缺補漏,提升水平
    2021-11-11
  • Java?六類運算符詳解

    Java?六類運算符詳解

    這篇文章主要介紹了Java?六類運算符,在?Java?語言中,運算符有算數(shù)運算符、關系運算符、邏輯運算符、賦值運算符、字符串連接運算符、條件運算符,感興趣的朋友可以閱讀一下
    2023-03-03
  • IDEA設置maven修改settings.xml配置文件無法加載倉庫的解決方案

    IDEA設置maven修改settings.xml配置文件無法加載倉庫的解決方案

    這篇文章主要介紹了IDEA設置maven修改settings.xml配置文件無法加載倉庫的解決方案,幫助大家更好的利用IDEA進行JAVA的開發(fā)學習,感興趣的朋友可以了解下
    2021-01-01

最新評論