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 version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="mainTask" class="guo.MainTask" />
- <bean id="mainJob"
- class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject">
- <ref bean="mainTask" />
- </property>
- <property name="targetMethod">
- <value>execute</value>
- </property>
- </bean>
- <bean id="timeTrigger"
- class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail">
- <ref bean="mainJob" />
- </property>
- <property name="cronExpression">
- <value>0/30 * * ? * *</value>
- </property>
- </bean>
- <bean id="sfb"
- class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref local="timeTrigger" />
- </list>
- </property>
- </bean>
- </beans>
- xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <welcome-file-list>
- <welcome-file>index.jspwelcome-file>
- welcome-file-list>
- <context-param>
- <param-name>contextConfigLocationparam-name>
- <param-value>/WEB-INF/TimerConfig.xmlparam-value>
- context-param>
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- listener-class>
- listener>
- web-app>
- package guo;
- public class MainTask {
- public void execute(){
- System.out.println("do the "+System.currentTimeMillis());
- }
- }