两篇博客:
    http://blog.csdn.net/jijijiujiu123/article/details/9086847    网站同事写的(chenrui) 
    http://blog.csdn.net/maskice/article/details/1670070         进阶版    
 
    原理比较简单,基于Jcrontab,使用jar包是:Jcrontab-2.0-RC0.jar,详见附件。基于web.xml配置servlet,然后配置.properties文件,包含log4j、数据源等。
    Jcrontab的工作原理是配置一系列数据源,由Jcrontab按照定时规则去处理的类和程序。数据源的配置程序可以是写到文件中、数据库中或者XML文件中。(详见附件CSDN某博客)
    标准配置
    web.xml配置:
  1. <servlet>
  2. <servlet-name>LoadOnStartupServlet</servlet-name>
  3. <servlet-class>org.jcrontab.web.loadCrontabServlet</servlet-class>
  4. <init-param>
  5. <param-name>PROPERTIES_FILE</param-name>
  6. <!--此处路径是绝对路径 -->
  7. <param-value>C:\Users\pc\Workspaces\MyEclipse 8.5\jcrontab\src\jcrontab.properties</param-value>
  8. </init-param>
  9. <load-on-startup>1</load-on-startup>
  10. </servlet>
  11. <servlet-mapping>
  12. <servlet-name>LoadOnStartupServlet</servlet-name>
  13. <url-pattern>/Startup</url-pattern>
  14. </servlet-mapping>
   jcrontab.properties配置:
   
  1. #
  2. # Those are the parameters to the DAO
  3. #
  4. # FileSource:
  5. # org.jcrontab.data.file
  6. # org.jcrontab.data.datasource
  7. #
  8. # SQLSource:
  9. # org.jcrontab.data.GenericSQLSource.driver
  10. # org.jcrontab.data.GenericSQLSource.url
  11. # org.jcrontab.data.GenericSQLSource.password
  12. # org.jcrontab.data.datasource
  13. #
  14. org.jcrontab.data.file = {$HOME}.jcrontab/crontab
  15. org.jcrontab.data.datasource = org.jcrontab.data.FileSource
  16. org.jcrontab.Crontab.refreshFrequency = 3
  17. # Those lines are necessaty to parse the XML file
  18. #org.xml.sax.driver=org.apache.xerces.parsers.SAXParser
  19. # Those Lines are necessary to connect to postgresql and use it as DataSource
  20. #org.jcrontab.data.GenericSQLSource.driver = org.postgresql.Driver
  21. #org.jcrontab.data.GenericSQLSource.url = jdbc:postgresql://yourmachine.jcrontab.org:5432/jcrontab
  22. # Those Lines are necessary to connect to mysql and use it as DataSource
  23. #org.jcrontab.data.GenericSQLSource.driver = org.gjt.mm.mysql.Driver
  24. #org.jcrontab.data.GenericSQLSource.url = jdbc:mysql://yourmachine.jcrontab.org:3306/jcrontab
  25. #org.jcrontab.data.GenericSQLSource.username = iolalla
  26. #org.jcrontab.data.GenericSQLSource.password = yourpassword
  27. #org.jcrontab.data.datasource = org.jcrontab.data.GenericSQLSource
  28. #org.jcrontab.data.GenericSQLSource.dbDataSource=yourDS
  29. # Those lines are necesary to send mail
  30. #org.jcrontab.sendMail.to=iolalla@yahoo.com
  31. #org.jcrontab.sendMail.from=jcrontab@yoursystem.com
  32. #org.jcrontab.sendMail.smtp.host=smtp.yahoo.com
  33. #org.jcrontab.sendMail.smtp.user= yourSMTPusername
  34. #org.jcrontab.sendMail.smtp.password=yourSMTPpassword
  35. #Those lines defines the default Logger for the system
  36. #org.jcrontab.log.Logger=jcrontabplugin.jEditLogger
  37. org.jcrontab.log.Logger=org.jcrontab.log.Log4JLogger
  38. org.jcrontab.log.log4J.Properties={$HOME}.jcrontab/log4j.properties
  39. #org.jcrontab.data.FileOpener=file
  40. #Those parameters are to get the Holidays from the system
  41. #org.jcrontab.data.holidaysource=org.jcrontab.data.HoliDayFileSource
  42. #org.jcrontab.data.holidaysfilesource={$HOME}.jcrontab/holidays
  43. #To change this plz refer to java.text.SimpleDateFormat
  44. #org.jcrontab.data.dateFormat=dd/MM/yyyy
 
 通过阅读源码,我们可以看到loadcrontabServlet的主要功能就是从一个名为jcrontab.properties的文件中读取各种属性并初始化。
 
 
项目配置
    web.xml配置:
  1. <servlet>
  2. <servlet-name>servletjcrontab</servlet-name>
  3. <servlet-class>公司自定义包.jcrontab.ServletJcrontab</servlet-class>
  4. <init-param>
  5. <param-name>org.jcrontab.data.datasource</param-name>
  6. <param-value>公司自定义包.jcrontab.JcrontabSQLSource</param-value>
  7. </init-param>
  8. <load-on-startup>200</load-on-startup>
  9. </servlet>
  10. <servlet-mapping>
  11. <servlet-name>servletjcrontab</servlet-name>
  12. <url-pattern>/servletjcrontab</url-pattern>
  13. </servlet-mapping>
 
    我买网在这一步的处理方式略有不同,原理大体相同。自己封装了一下。
 
    刚才我们说过数据源的处理有三种方式,我买网采用数据库存储的方式。
    数据库的方式标准配置是在jcrontab.properties配置文件中配置各种url、driver....(配置数据源那一套),但是现有项目早已经有数据源无需重新配置。
    我买网自己实现而不读取jcrontab.properties中的数据源配置。
    
    jcrontab.properties:
  1. org.jcrontab.log.log4J.Properties=WEB-INF/classes/log4j.properties
  2. org.jcrontab.version=2.0.RC1
  3. org.jcrontab.log.Logger=org.jcrontab.log.Log4JLogger
  4. org.jcrontab.data.dateFormat=dd/MM/yyyy
  5. org.jcrontab.data.nodetype=58
  6. org.jcrontab.data.datasource = net.xinshi.jemall.jcrontab.JcrontabSQLSource
  7. org.jcrontab.Crontab.refreshFrequency =3
   jcrontab.properties的详细配置详见源码jar包中的文件。
 
 

附件列表

Jcrontab定时任务的更多相关文章

  1. Spring 定时任务Scheduled 开发详细图文

    Spring 定时任务Scheduled 开发 文章目录 一.前言 1.1 定时任务 1.2 开发环境 1.3 技术实现 二.创建包含WEB.xml 的Maven 项目 2.1 创建多模块项目task ...

  2. Java 定时任务 & 任务调度

    任务调度是指基于 给定时间点,给定时间间隔 或者 给定执行次数 自动执行任务. 方式1:通过 Thread 来实现 例如如下的代码,可以每隔 1000 毫秒做一次打印操作. public class ...

  3. Java定时任务的常用实现

    Java的定时任务有以下几种常用的实现方式: 1)Timer 2)ScheduledThreadPoolExecutor 3)Spring中集成Cron Quartz 接下来依次介绍这几类具体实现的方 ...

  4. [转]Java实现定时任务的三种方法

    在应用里经常都有用到在后台跑定时任务的需求.举个例子,比如需要在服务后台跑一个定时任务来进行非实时计算,清除临时数据.文件等.在本文里,我会给大家介绍3种不同的实现方法: 普通thread实现 Tim ...

  5. 使用python crontab设置linux定时任务

    熟悉linux的朋友应该知道在linux中可以使用crontab设置定时任务.可以通过命令crontab -e编写任务.当然也可以直接写配置文件设置任务. 但是有时候希望通过脚本自动设置,比如我们应用 ...

  6. C#定时任务组件之FluentScheduler

    FluentScheduler是.NET开源处理定时任务组件 1.任务的创建注册 public static void TaskActionByMinutes(Action action, int c ...

  7. 浅谈 linux 例行性工作 crontab (linux定时任务)

    定时任务大家都挺说过,就好比你手机上的闹钟,到了指定的时候就会响起. 今天在对redis缓存进行定时储存时又操作了一把,发现一些细节,写的不好.大家就将就看吧, 首先 简单介绍一下linux 例行性工 ...

  8. SpringMVC中定时任务配置

    在项目中使用定时任务是常有的事,比如每天定时进行数据同步或者备份等等. 以前在从事C语言开发的时候,定时任务都是通过写个shell脚本,然后添加到linux定时任务中进行调度的. 现在使用Spring ...

  9. springboot(九):定时任务

    在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容,springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现 1.pom包配置 pom包里面只需要引入springboot ...

随机推荐

  1. C++_标准模板库STL概念介绍1-建立感性认知

    标准模板库的英文缩写是STL,即Standard Template Library. STL里面有什么呢? 它提供了一组表示容器.迭代器.函数对象和算法的模板. 容器是一个与数组类似的单元,可以存储若 ...

  2. 浅谈C#数组(一)

    如果需要使用同一类型的多个对象,可以使用数组和集合(后面介绍).C#用特殊的记号声明,初始化和使用数组.Array类在后台发挥作用,它为数组中的元素排序和过滤提供了多个方法.使用枚举器,可以迭代数组中 ...

  3. no git binary found in $path(已解决,但是还有疑问)

    跟同行研究个项目代码,他把代码打包发我后,我解压到本地,路径和我本地个人项目路径基本相同, 但是当执行npm install时,就报了 no git binary found in $path ,这个 ...

  4. 简单探究一下window下的wifi各种东西

    保存地方在哪里 C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...

  5. POJ - 2891 中国剩余定理

    \(mod\)存在不互素情况下的CRT #include<iostream> #include<algorithm> #include<cstdio> #inclu ...

  6. [转] electron实战开发详细流程

    [From] http://www.myk3.com/arc-8856.html 很久没有更新博客,人越来越懒了,唉 说好做的electron教程距离上次玩electron已经过去了好几个月了.. 这 ...

  7. (转)Openldap相关精品文章

    1.运维咖啡吧 https://mp.weixin.qq.com/s__biz=MzU5MDY1MzcyOQ==&mid=2247483754&idx=1&sn=9f20d45 ...

  8. 初用msui.js

    MSui,基于 Framework7 开发,组件功能使用Zepto库提供.定位轻量级的ui库 简单的使用MSui组件只需要引入所提供的CDN则可 <link rel="styleshe ...

  9. 搭建Flask+Vue及配置Vue 基础路由

    最近一直在看关于Python的东西,准备多学习点东西.以前的项目是用Vue+Java写的,所以试着在升级下系统的前提下.能不能使用Python+Vue做一遍. 选择Flask的原因是不想随大流,并且比 ...

  10. js数组方法详解

    Array对象的方法-25个 /*js数组方法详解 */ /* * 1 concat() 用于连接多个数组或者值-------------- * 2 copyWithin() 方法用于从数组的指定位置 ...