快速业务通道

彻底理解Spring的定制任务 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-22
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

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号