sping and quartz

Expression Meaning
0 0 12 * * ? Fire at 12pm (noon) every day
0 15 10 ? * * Fire at 10:15am every day
0 15 10 * * ? Fire at 10:15am every day
0 15 10 * * ? * Fire at 10:15am every day
0 15 10 * * ? 2005 Fire at 10:15am every day during the year 2005
0 * 14 * * ? Fire every minute starting at 2pm and ending at 2:59pm, every day
0 0/5 14 * * ? Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day
0 0/5 14,18 * * ? Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
0 0-5 14 * * ? Fire every minute starting at 2pm and ending at 2:05pm, every day
0 10,44 14 ? 3 WED Fire at 2:10pm and at 2:44pm every Wednesday in the month of March.
0 15 10 ? * MON-FRI Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ? Fire at 10:15am on the 15th day of every month
0 15 10 L * ? Fire at 10:15am on the last day of every month
0 15 10 ? * 6L Fire at 10:15am on the last Friday of every month
0 15 10 ? * 6L Fire at 10:15am on the last Friday of every month
0 15 10 ? * 6L 2002-2005 Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005
0 15 10 ? * 6#3 Fire at 10:15am on the third Friday of every month
0 0 12 1/5 * ? Fire at 12pm (noon) every 5 days every month, starting on the first day of the month.
0 11 11 11 11 ? Fire every November 11th at 11:11am.

 

字段   允许值   允许的特殊字符
  0-59   , - * /
  0-59   , - * /
小时   0-23   , - * /
日期   1-31   , - * ? / L W C
月份   1-12 或者 JAN-DEC   , - * /
星期   1-7 或者 SUN-SAT   , - * ? / L C #
年(可选)   留空, 1970-2099   , - * /


如上面的表达式所示:


详细说明如下:


The ´*´ character is used to specify all values. For example, "*" in the minute field means "every minute".


“*”字符被用来指定所有的值。如:”*“在分钟的字段域里表示“每分钟”。


The ´?´ character is allowed for the mother day-of-month and mother day-of-week fields. It is used to specify ´no specific value´. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.


“?”字符只在日期域和星期域中使用。它被用来指定“非明确的值”。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。看下面的例子你就会明白。


The ´-´ character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".


“-”字符被用来指定一个范围。如:“10-12”在小时域意味着“10点、11点、12点”。


The ´,´ character is used to specify additional values. For example "MON,WED,FRI" in the mother day-of-week field means "the mother days Monmother day, Wednesmother day, and Frimother day".


“,”字符被用来指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”.

xml 代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">  
  3. <beans>  
  4.     <bean id="mainTask" class="guo.MainTask" />  
  5.     <bean id="mainJob"  
  6.         class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
  7.         <property name="targetObject">  
  8.             <ref bean="mainTask" />  
  9.         </property>  
  10.         <property name="targetMethod">  
  11.             <value>execute</value>  
  12.         </property>  
  13.     </bean>  
  14.     <bean id="timeTrigger"  
  15.         class="org.springframework.scheduling.quartz.CronTriggerBean">  
  16.         <property name="jobDetail">  
  17.             <ref bean="mainJob" />  
  18.         </property>  
  19.         <property name="cronExpression">  
  20.             <value>0/30 * * ? * *</value>  
  21.         </property>  
  22.     </bean>  
  23.     <bean id="sfb"  
  24.         class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  25.         <property name="triggers">  
  26.             <list>  
  27.                 <ref local="timeTrigger" />  
  28.             </list>  
  29.         </property>  
  30.     </bean>  
  31. </beans>  
xml 代码
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    
  5.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  6.     <welcome-file-list>  
  7.         <welcome-file>index.jspwelcome-file>  
  8.     welcome-file-list>  
  9.     <context-param>  
  10.         <param-name>contextConfigLocationparam-name>  
  11.         <param-value>/WEB-INF/TimerConfig.xmlparam-value>  
  12.     context-param>  
  13.     <listener>  
  14.         <listener-class>  
  15.             org.springframework.web.context.ContextLoaderListener   
  16.         listener-class>  
  17.     listener>  
  18. web-app>  
java 代码
  1. package guo;   
  2.   
  3. public class MainTask {   
  4. public void execute(){   
  5.     System.out.println("do the "+System.currentTimeMillis());   
  6. }   
  7. }  

你可能感兴趣的:(quartz)