/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* 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.quartz.examples.example9; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.JobDetail;
import org.quartz.JobListener;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SchedulerMetaData;
import org.quartz.SimpleTrigger;
import org.quartz.examples.example2.SimpleJob;
import org.quartz.impl.StdSchedulerFactory; /**
* Demonstrates the behavior of <code>JobListener</code>s. In particular,
* this example will use a job listener to trigger another job after one
* job succesfully executes.
*
*/
public class ListenerExample { public void run() throws Exception {
Logger log = LoggerFactory.getLogger(ListenerExample.class); log.info("------- Initializing ----------------------"); // First we must get a reference to a scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler(); log.info("------- Initialization Complete -----------"); log.info("------- Scheduling Jobs -------------------"); // schedule a job to run immediately
JobDetail job = new JobDetail("job1", "group1", SimpleJob.class);
SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1",
new Date(),
null,
0,
0);
// Set up the listener
JobListener listener = new Job1Listener();
sched.addJobListener(listener); // make sure the listener is associated with the job
job.addJobListener(listener.getName()); // schedule the job to run
sched.scheduleJob(job, trigger); // All of the jobs have been added to the scheduler, but none of the jobs
// will run until the scheduler has been started
log.info("------- Starting Scheduler ----------------");
sched.start(); // wait 30 seconds:
// note: nothing will run
log.info("------- Waiting 30 seconds... --------------");
try {
// wait 30 seconds to show jobs
Thread.sleep(30L * 1000L);
// executing...
} catch (Exception e) {
} // shut down the scheduler
log.info("------- Shutting Down ---------------------");
sched.shutdown(true);
log.info("------- Shutdown Complete -----------------"); SchedulerMetaData metaData = sched.getMetaData();
log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs."); } public static void main(String[] args) throws Exception { ListenerExample example = new ListenerExample();
example.run();
} }

  

/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* 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.quartz.examples.example9; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger; /**
* @author wkratzer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Job1Listener implements JobListener { private static Logger _log = LoggerFactory.getLogger(Job1Listener.class); public String getName() {
return "job1_to_job2";
} public void jobToBeExecuted(JobExecutionContext inContext) {
_log.info("Job1Listener says: Job Is about to be executed.");
} public void jobExecutionVetoed(JobExecutionContext inContext) {
_log.info("Job1Listener says: Job Execution was vetoed.");
} public void jobWasExecuted(JobExecutionContext inContext,
JobExecutionException inException) {
_log.info("Job1Listener says: Job was executed."); // Simple job #2
JobDetail job2 =
new JobDetail("job2",
Scheduler.DEFAULT_GROUP,
SimpleJob2.class); // Simple trigger to fire immediately
SimpleTrigger trigger =
new SimpleTrigger("job2Trigger",
Scheduler.DEFAULT_GROUP,
new Date(),
null,
0,
0L); try {
// schedule the job to run!
inContext.getScheduler().scheduleJob(job2, trigger);
} catch (SchedulerException e) {
_log.warn("Unable to schedule job2!");
e.printStackTrace();
} } }

  

/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* 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.quartz.examples.example9; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; /**
* <p>
* This is just a simple job that gets fired off many times by example 1
* </p>
*
* @author Bill Kratzer
*/
public class SimpleJob1 implements Job { private static Logger _log = LoggerFactory.getLogger(SimpleJob1.class); /**
* Empty constructor for job initilization
*/
public SimpleJob1() {
} /**
* <p>
* Called by the <code>{@link org.quartz.Scheduler}</code> when a
* <code>{@link org.quartz.Trigger}</code> fires that is associated with
* the <code>Job</code>.
* </p>
*
* @throws JobExecutionException
* if there is an exception while executing the job.
*/
public void execute(JobExecutionContext context)
throws JobExecutionException { // This job simply prints out its job name and the
// date and time that it is running
String jobName = context.getJobDetail().getFullName();
_log.info("SimpleJob1 says: " + jobName + " executing at " + new Date());
} }

  

/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* 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.quartz.examples.example9; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; /**
* <p>
* This is just a simple job that gets fired off many times by example 1
* </p>
*
* @author Bill Kratzer
*/
public class SimpleJob2 implements Job { private static Logger _log = LoggerFactory.getLogger(SimpleJob2.class); /**
* Empty constructor for job initilization
*/
public SimpleJob2() {
} /**
* <p>
* Called by the <code>{@link org.quartz.Scheduler}</code> when a
* <code>{@link org.quartz.Trigger}</code> fires that is associated with
* the <code>Job</code>.
* </p>
*
* @throws JobExecutionException
* if there is an exception while executing the job.
*/
public void execute(JobExecutionContext context)
throws JobExecutionException { // This job simply prints out its job name and the
// date and time that it is running
String jobName = context.getJobDetail().getFullName();
_log.info("SimpleJob2 says: " + jobName + " executing at " + new Date());
} }

  

[INFO] 02 二月 03:56:06.271 下午 main [org.quartz.examples.example9.ListenerExample]
------- Initializing ---------------------- [INFO] 02 二月 03:56:06.293 下午 main [org.quartz.simpl.SimpleThreadPool]
Job execution threads will use class loader of thread: main [INFO] 02 二月 03:56:06.307 下午 main [org.quartz.core.SchedulerSignalerImpl]
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl [INFO] 02 二月 03:56:06.308 下午 main [org.quartz.core.QuartzScheduler]
Quartz Scheduler v.1.8.5 created. [INFO] 02 二月 03:56:06.309 下午 main [org.quartz.simpl.RAMJobStore]
RAMJobStore initialized. [INFO] 02 二月 03:56:06.310 下午 main [org.quartz.core.QuartzScheduler]
Scheduler meta-data: Quartz Scheduler (v1.8.5) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. [INFO] 02 二月 03:56:06.310 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' [INFO] 02 二月 03:56:06.310 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler version: 1.8.5 [INFO] 02 二月 03:56:06.310 下午 main [org.quartz.examples.example9.ListenerExample]
------- Initialization Complete ----------- [INFO] 02 二月 03:56:06.311 下午 main [org.quartz.examples.example9.ListenerExample]
------- Scheduling Jobs ------------------- [INFO] 02 二月 03:56:06.314 下午 main [org.quartz.examples.example9.ListenerExample]
------- Starting Scheduler ---------------- [INFO] 02 二月 03:56:06.314 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. [INFO] 02 二月 03:56:06.314 下午 main [org.quartz.examples.example9.ListenerExample]
------- Waiting 30 seconds... -------------- [DEBUG] 02 二月 03:56:06.316 下午 DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.SimpleJobFactory]
Producing instance of Job 'group1.job1', class=org.quartz.examples.example2.SimpleJob [INFO] 02 二月 03:56:06.319 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example9.Job1Listener]
Job1Listener says: Job Is about to be executed. [DEBUG] 02 二月 03:56:06.319 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.core.JobRunShell]
Calling execute on job group1.job1 [INFO] 02 二月 03:56:06.320 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example2.SimpleJob]
SimpleJob says: group1.job1 executing at Tue Feb 02 15:56:06 CST 2016 [INFO] 02 二月 03:56:06.320 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example9.Job1Listener]
Job1Listener says: Job was executed. [DEBUG] 02 二月 03:56:06.321 下午 DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.SimpleJobFactory]
Producing instance of Job 'DEFAULT.job2', class=org.quartz.examples.example9.SimpleJob2 [DEBUG] 02 二月 03:56:06.321 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.core.JobRunShell]
Calling execute on job DEFAULT.job2 [INFO] 02 二月 03:56:06.321 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.examples.example9.SimpleJob2]
SimpleJob2 says: DEFAULT.job2 executing at Tue Feb 02 15:56:06 CST 2016 [DEBUG] 02 二月 03:56:07.308 下午 Timer-0 [org.quartz.utils.UpdateChecker]
Checking for available updated version of Quartz... [INFO] 02 二月 03:56:36.314 下午 main [org.quartz.examples.example9.ListenerExample]
------- Shutting Down --------------------- [INFO] 02 二月 03:56:36.314 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down. [INFO] 02 二月 03:56:36.314 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused. [DEBUG] 02 二月 03:56:36.315 下午 main [org.quartz.simpl.SimpleThreadPool]
shutdown complete [INFO] 02 二月 03:56:36.315 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete. [INFO] 02 二月 03:56:36.315 下午 main [org.quartz.examples.example9.ListenerExample]
------- Shutdown Complete ----------------- [INFO] 02 二月 03:56:36.315 下午 main [org.quartz.examples.example9.ListenerExample]
Executed 2 jobs. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-10 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-3 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-8 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-4 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-5 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-7 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-9 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.495 下午 DefaultQuartzScheduler_Worker-6 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.546 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 03:56:36.546 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down.

  

Quartz1.8.5例子(九)的更多相关文章

  1. Quartz1.8.5例子(二)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  2. scrapy-splash抓取动态数据例子九

    一.介绍 本例子用scrapy-splash抓取众视网网站给定关键字抓取咨询信息. 给定关键字:个性化:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二.网站信 ...

  3. 从零开始学习Node.js例子九 设置HTTP头

    server.js //basic server的配置文件 ; var server = require('./basicserver').createServer(); server.useFavI ...

  4. Quartz1.8.5例子(十四)

    org.quartz.scheduler.instanceName: PriorityExampleScheduler # Set thread count to 1 to force Trigger ...

  5. Quartz1.8.5例子(十一)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  6. Quartz1.8.5例子(十)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  7. Quartz1.8.5例子(八)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  8. Quartz1.8.5例子(七)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

  9. Quartz1.8.5例子(六)

    /* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...

随机推荐

  1. TM1668 Led 驱动芯片源程序

    #define P_1668DAT_In RA0 //数据输入端口 #define P_1668DAT LATA0 //数据输出端口 #define P_1668CLK LATA1 #define P ...

  2. Cocos2d-x 3.1.1 学习日志4--cocos2d-x解决中文乱码问题的几种办法

    做个打飞机的游戏,由于版本号太新,网上基本没有教教程,我的版本号是cocos2d-x 3.1.1的.今天遇到cocos2dx中中文乱码的问题.无奈仅仅好Google百度寻求答案,明确了这个问题的缘由. ...

  3. 设计模式 - 观察者模式(Observer Pattern) 详细说明

    观察者模式(Observer Pattern) 详细说明 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26583157 版权全部 ...

  4. linux文件的隐藏属性:chattr

    1. 文件的隐藏属性 linux除了9个权限外,还有些隐藏属性, 使用chattr命令来设置. 使用方法: $ chattr +-=[ASacDdIijsTtu] + : 添加一个特殊參数 - :   ...

  5. go 初使用

    hello.go package main import "fmt" func main(){ fmt.Println("hello world") 直接运行 ...

  6. WSDL阅读方法

    我们以天气预报WebService服务为例,来看看怎么阅读一个wsdl文档. 打开一个wsdl文档后,先看底部. binding在这里: portType在这里: 好了,看了上面的,我们来说说wsdl ...

  7. svn项目冲突时显示无法加载项目的解决方法

    1.无法加载的项目会显示成灰色.这是右键点击编辑  打开后去掉乱字符. 2.完成后会有红色的叹号 这是右键 找到解决冲突即可 然后提交

  8. Oracle存储过程中不支持DML语言的解决方法(针对遇见的DROP关键字)

    ---存储过程中的原语句: ---删除表 DROP TABLE A_NEWTDDATA; --报错 经查询:存储过程不支持DML语言: 解决方法: execute immediate 'DROP TA ...

  9. JS0热身运动

    热身热身小知识点: JS中如何获取元素: 1 通过ID名称来获取:document get element by id  -->document.getElementById() 2 .... ...

  10. 自动显示git分支--安装oh-my-zsh(Ubuntu环境)

    1,安装zsh sudo apt-get install zsh 2,克隆项目 git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...