timerTask = timerTask;
}
/**
* Return the TimerTask to schedule.
*/
public TimerTask getTimerTask() {
return timerTask;
}
/**
* Set the delay before starting the task for the first time,
* in milliseconds. Default is 0,immediately starting the
* task after successful scheduling.
*/
public void setDelay( long delay) {
this .delay = delay;
}
/**
* Return the delay before starting the job for the first time.
*/
public long getDelay() {
return delay;
}
/**
* Set the period between repeated task executions,in milliseconds.
* Default is 0,leading to one-time execution. In case of a positive
* value,the task will be executed repeatedly,with the given interval
* inbetween executions.
*
彻底理解Spring的定制任务(3)
时间:2010-12-26 爬虫工作室
Note that the semantics of the period vary between fixed-rate .
* and fixed-delay execution.
* @see #setFixedRate
*/
public void setPeriod( long period) {
this .period = period;
}
/**
* Return the period between repeated task executions.
*/
public long getPeriod() {
return period;
}
/**
* Set whether to schedule as fixed-rate execution,rather than
* fixed-delay execution. Default is "false",i.e. fixed delay.
*
See Timer javadoc for details on those execution modes.
* @see java.util.Timer#schedule(TimerTask,long,long)
* @see java.util.Timer#scheduleAtFixedRate(TimerTask,long,long)
*/
public void setFixedRate( boolean fixedRate) {
this .fixedRate = fixedRate;
}
/**
* Return whether to schedule as fixed-rate execution.
*/
public boolean isFixedRate() {
return fixedRate;
}
}
说实话这个类也没什么,只是简单的包装了我们的timertask,里面也就只有几个属性,一个是时间片,一个是任务等。
真正运行我们的任务的类是:
Java代码:
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License,Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.timer;
import java.util.Timer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
/**
* FactoryBean that sets up a JDK 1.3+ Timer and exposes it for bean references.
*
*
彻底理解Spring的定制任务(4)
时间:2010-12-26 爬虫工作室
Allows for registration of ScheduledTimerTasks,automatically starting
* the Timer on initialization and cancelling it on destruction of the context.
* In scenarios tha
|