/*
* 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. iOS实用技能扩展-集成支付宝

    前奏 现在随着移动开发的快速发展,移动支付变得越来越流行与必不可少.最近做了一个关于支付宝支付功能的应用,在使用支付宝的过程中,遇到一些不必要的弯路,因此,写了这篇文章总结一下关于iOS中如何开发使用 ...

  2. c#类的初始化顺序

    本文转载:http://www.cnblogs.com/ybhcolin/archive/2010/09/24/1834219.html c#类的初始化顺序 类在初始化时的执行顺序,依次如下: 1: ...

  3. Android Dev

    [2015-04-22 13:30:37 - branch_1.5.1_WelcomeActivity] R.java was modified manually! Reverting to gene ...

  4. JMeter对Oracle数据库进行压力测试

    步骤 (1)复制ORACLE的JDBC驱动JAR包文件(ojdbc14.jar)到JMeter的lib目录下. (2)运行jmeter.bat (3)建立线程组:右键测试计划->添加->T ...

  5. App升级时数据库的迁移更新

    前一段时间在进行App升级的时候,由于一开始版本初期没有考虑完善,导致走了很多弯路,后来经过自己的一些思考,总结出了一些在app升级的时候,数据库内文件同步保持更新的经验,希望能给大家带来帮助. 总体 ...

  6. 使用gradle构建java项目

    gradle是什么东东 gradle是继ant,maven之后另外一种的面向java的自动化项目构建工具,他是基于groovy语言的.相对于ant,maven,gradle显得更加简单. 安装grad ...

  7. 菱形实现气泡Bubble,菱形画箭头,菱形画三角形

    菱形实现气泡Bubble,菱形画箭头,菱形画三角形 >>>>>>>>>>>>>>>>>>&g ...

  8. 微信分组群发图文40152,微信分组群发图文invalid group id hint

    微信分组群发40152,微信分组群发invalid group id hint >>>>>>>>>>>>>>> ...

  9. Unity3D中读取CSV文件

    直接上代码 Part1: using UnityEngine; using System.IO; using System.Collections.Generic; public class CSV ...

  10. 学习java随笔第九篇:java异常处理

    在java中的异常处理和c#中的异常处理是一样的都是用try-catch语句. 基本语法如下 try { //此处是可能出现异常的代码 } catch(Exception e) { //此处是如果发生 ...