创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
前言:Spring中使用Quartz 有两种方式,一种是继承特定的基类:org.springframework.scheduling.quartz.QuartzJobBean,另一种则不需要,(推荐使用第二种)。下面分别介绍。
1、作业类继承 org.springframework.scheduling.quartz.QuartzJobBean
第一步:定义作业类
java代码
import java.text.SimpleDateFormat; import java.util.Date; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.scheduling.quartz.QuartzJobBean; public class Job1 extends QuartzJobBean{ //这个参数值由xml配置传过来 private int timeout; public void setTimeout(int timeout) { this.timeout = timeout; } @Override protected void executeInternal(JobExecutionContext content) throws JobExecutionException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(sdf.format(new Date()) + "job1执行" + "这是xml里给timeout赋值" + timeout); } }
新闻名称:Spring中使用Quartz实现任务调度-创新互联
分享地址:https://www.cdcxhl.com/article28/joojp.html
成都网站建设公司_创新互联,为您提供网站营销、企业网站制作、建站公司、网站策划、品牌网站设计、移动网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联