国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
spring執(zhí)行定時(shí)任務(wù)
定義一個(gè)任務(wù)是很簡(jiǎn)單的實(shí)現(xiàn)TimerTask的run方法就可以了.
如下:SayHelloTask.java
package test.timerTask;
import java.util.TimerTask;
public class SayHelloTask extends TimerTask {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("測(cè)試TimerTask : Hello !!");
}
}
然后是配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "spring-beans.dtd" >
<beans>
<bean id="sayHelloTask" class="test.timerTask.SayHelloTask"></bean>
<bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="timerTask">
<ref bean="sayHelloTask"/>
</property>
<!-- 任務(wù)執(zhí)行周期 2m 關(guān)于一些任務(wù)的參數(shù)請(qǐng)參考JDK doc文檔和Spring相關(guān)文檔-->
<property name="period">
<value>2000</value>
</property>
<!-- 延時(shí)1m 執(zhí)行任務(wù) -->
<property name="delay">
<value>1000</value>
</property>
</bean>
<!-- 啟動(dòng)定時(shí)器 -->
<bean id="timerBean" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="scheduledTask"/>
</list>
</property>
</bean>
</beans>
測(cè)試類如下:TestApp.java
package test.timerTask;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestApp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("test/timerTask/javaTimer.xml");
//   ApplicationContext context2 = new ClassPathXmlApplicationContext("test/timerTask/quartzTimer.xml");
}
// 只要加載配置文件就可以了,
}
使用Java中的定時(shí)器比較簡(jiǎn)單,其提供的任務(wù)也比較簡(jiǎn)單, 下面來看看使用quartz來執(zhí)行一個(gè)復(fù)雜的任務(wù).
首先制定一個(gè)任務(wù), 實(shí)現(xiàn)QuartzJobBean中的方法.
package test.timerTask;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class SayHelloTaskUsingQuartz extends QuartzJobBean {
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("使用Quartz 認(rèn)為調(diào)度: Hello!!");
}
}
配置代碼如下:quartzTimer.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "spring-beans.dtd" >
<beans>
<bean id="sayHelloJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>test.timerTask.SayHelloTaskUsingQuartz</value>
</property>
</bean>
<!-- 關(guān)鍵在如下兩個(gè)觸發(fā)器的配置 -->
<!-- 類似于Java的簡(jiǎn)單觸發(fā)器 -->
<bean id="helloTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="sayHelloJob"/>
</property>
<property name="startDelay">
<value>1000</value>
</property>
<property name="repeatInterval">
<value>3000</value>
</property>
</bean>
<!-- 復(fù)雜觸發(fā)器 -->
<bean id="helloCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="sayHelloJob"/>
</property>
<property name="cronExpression">
<!-- 關(guān)鍵在配置此表達(dá)式 -->
<value>0 49 15 * * ?</value>
</property>
</bean>
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<ref bean="helloCronTrigger"/>
</property>
</bean>
</beans>
關(guān)于簡(jiǎn)單觸發(fā)器和復(fù)雜觸發(fā)器,查考下面的解釋:
Quartz設(shè)計(jì)者做了一個(gè)設(shè)計(jì)選擇來從調(diào)度分離開作業(yè)。Quartz中的觸發(fā)器用來告訴調(diào)度程序作業(yè)什么時(shí)候觸發(fā)??蚣芴峁┝艘话延|發(fā)器類型,但兩個(gè)最常用的是SimpleTrigger和CronTrigger。SimpleTrigger為需要簡(jiǎn)單打火調(diào)度而設(shè)計(jì)。典型地,如果你需要在給定的時(shí)間和重復(fù)次數(shù)或者兩次打火之間等待的秒數(shù)打火一個(gè)作業(yè),那么SimpleTrigger適合你。另一方面,如果你有許多復(fù)雜的作業(yè)調(diào)度,那么或許需要CronTrigger。
CronTrigger是基于Calendar-like調(diào)度的。當(dāng)你需要在除星期六和星期天外的每天上午10點(diǎn)半執(zhí)行作業(yè)時(shí),那么應(yīng)該使用CronTrigger。正如它的名字所暗示的那樣,CronTrigger是基于Unix克隆表達(dá)式的。
作為一個(gè)例子,下面的Quartz克隆表達(dá)式將在星期一到星期五的每天上午10點(diǎn)15分執(zhí)行一個(gè)作業(yè)。
0 15 10 ? * MON-FRI
下面的表達(dá)式
0 15 10 ? * 6L 2002-2005
將在2002年到2005年的每個(gè)月的最后一個(gè)星期五上午10點(diǎn)15分執(zhí)行作業(yè)。
你不可能用SimpleTrigger來做這些事情。你可以用兩者之中的任何一個(gè),但哪個(gè)跟合適則取決于你的調(diào)度需要。
更多詳細(xì)介紹參考此處:
關(guān)于cronExpression的介紹:
字段   允許值   允許的特殊字符
秒   0-59   , - * /
分   0-59   , - * /
小時(shí)   0-23   , - * /
日期   1-31   , - * ? / L W C
月份   1-12 或者 JAN-DEC   , - * /
星期   1-7 或者 SUN-SAT   , - * ? / L C #
年(可選)   留空, 1970-2099   , - * /
如上面的表達(dá)式所示:
詳細(xì)說明如下:
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.
“?”字符只在日期域和星期域中使用。它被用來指定“非明確的值”。當(dāng)你需要通過在這兩個(gè)域中的一個(gè)來指定一些東西的時(shí)候,它是有用的??聪旅娴睦幽憔蜁?huì)明白。
The ′-′ character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
“-”字符被用來指定一個(gè)范圍。如:“10-12”在小時(shí)域意味著“10點(diǎn)、11點(diǎn)、12點(diǎn)”。
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”在星期域里表示”星期一、星期三、星期五”.
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
spring定時(shí)服務(wù)講解
spring中集成TimerTask執(zhí)行定時(shí)任務(wù)
Spring 中的定時(shí)器TimerTask 與 quartz的使用
Spring的任務(wù)調(diào)度服務(wù)實(shí)例講解
Spring定時(shí)任務(wù)的幾種實(shí)現(xiàn)
Spring-3.2.4 + Quartz-2.2.0集成實(shí)例
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服