/*
* 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.example1; 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 says "Hello" to the world.
* </p>
*
* @author Bill Kratzer
*/
public class HelloJob implements Job { private static Logger _log = LoggerFactory.getLogger(HelloJob.class); /**
* <p>
* Empty constructor for job initilization
* </p>
* <p>
* Quartz requires a public empty constructor so that the
* scheduler can instantiate the class whenever it needs.
* </p>
*/
public HelloJob() {
} /**
* <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 { // Say Hello to the World and display the date/time
_log.info("Hello World! - " + 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.example1; import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory; /**
* This Example will demonstrate how to start and shutdown the Quartz
* scheduler and how to schedule a job to run in Quartz.
*
* @author Bill Kratzer
*/
public class SimpleExample { public void run() throws Exception {
Logger log = LoggerFactory.getLogger(SimpleExample.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 -------------------"); // computer a time that is on the next round minute
Date runTime = TriggerUtils.getEvenMinuteDate(new Date()); // define the job and tie it to our HelloJob class
JobDetail job = new JobDetail("job1", "group1", HelloJob.class); // Trigger the job to run on the next round minute
SimpleTrigger trigger =
new SimpleTrigger("trigger1", "group1", runTime); // Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);
log.info(job.getFullName() + " will run at: " + runTime); // Start up the scheduler (nothing can actually run until the
// scheduler has been started)
sched.start();
log.info("------- Started Scheduler -----------------"); // wait long enough so that the scheduler as an opportunity to
// run the job!
log.info("------- Waiting 90 seconds... -------------");
try {
// wait 90 seconds to show jobs
Thread.sleep(90L * 1000L);
// executing...
} catch (Exception e) {
} // shut down the scheduler
log.info("------- Shutting Down ---------------------");
sched.shutdown(true);
log.info("------- Shutdown Complete -----------------");
} public static void main(String[] args) throws Exception { SimpleExample example = new SimpleExample();
example.run(); } }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="default" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c]%n%m%n%n"/>
</layout>
</appender> <logger name="org.quartz">
<level value="debug" />
</logger> <root>
<level value="debug" />
<appender-ref ref="default" />
</root> </log4j:configuration>

执行结果

[INFO] 02 二月 01:17:54.674 下午 main [org.quartz.examples.example1.SimpleExample]
------- Initializing ---------------------- [INFO] 02 二月 01:17:54.701 下午 main [org.quartz.simpl.SimpleThreadPool]
Job execution threads will use class loader of thread: main [INFO] 02 二月 01:17:54.714 下午 main [org.quartz.core.SchedulerSignalerImpl]
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl [INFO] 02 二月 01:17:54.715 下午 main [org.quartz.core.QuartzScheduler]
Quartz Scheduler v.1.8.5 created. [INFO] 02 二月 01:17:54.716 下午 main [org.quartz.simpl.RAMJobStore]
RAMJobStore initialized. [INFO] 02 二月 01:17:54.717 下午 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 二月 01:17:54.717 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' [INFO] 02 二月 01:17:54.717 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler version: 1.8.5 [INFO] 02 二月 01:17:54.717 下午 main [org.quartz.examples.example1.SimpleExample]
------- Initialization Complete ----------- [INFO] 02 二月 01:17:54.717 下午 main [org.quartz.examples.example1.SimpleExample]
------- Scheduling Jobs ------------------- [INFO] 02 二月 01:17:54.723 下午 main [org.quartz.examples.example1.SimpleExample]
group1.job1 will run at: Tue Feb 02 13:18:00 CST 2016 [INFO] 02 二月 01:17:54.723 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. [INFO] 02 二月 01:17:54.723 下午 main [org.quartz.examples.example1.SimpleExample]
------- Started Scheduler ----------------- [INFO] 02 二月 01:17:54.723 下午 main [org.quartz.examples.example1.SimpleExample]
------- Waiting 90 seconds... ------------- [DEBUG] 02 二月 01:17:55.715 下午 Timer-0 [org.quartz.utils.UpdateChecker]
Checking for available updated version of Quartz... [DEBUG] 02 二月 01:18:00.001 下午 DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.SimpleJobFactory]
Producing instance of Job 'group1.job1', class=org.quartz.examples.example1.HelloJob [DEBUG] 02 二月 01:18:00.019 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.core.JobRunShell]
Calling execute on job group1.job1 [INFO] 02 二月 01:18:00.030 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.examples.example1.HelloJob]
Hello World! - Tue Feb 02 13:18:00 CST 2016 [INFO] 02 二月 01:19:24.723 下午 main [org.quartz.examples.example1.SimpleExample]
------- Shutting Down --------------------- [INFO] 02 二月 01:19:24.723 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down. [INFO] 02 二月 01:19:24.723 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused. [DEBUG] 02 二月 01:19:24.723 下午 main [org.quartz.simpl.SimpleThreadPool]
shutdown complete [INFO] 02 二月 01:19:24.723 下午 main [org.quartz.core.QuartzScheduler]
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete. [INFO] 02 二月 01:19:24.724 下午 main [org.quartz.examples.example1.SimpleExample]
------- Shutdown Complete ----------------- [DEBUG] 02 二月 01:19:25.000 下午 DefaultQuartzScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-4 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-8 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-2 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-5 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-7 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-6 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-9 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-3 [org.quartz.simpl.SimpleThreadPool]
WorkerThread is shut down. [DEBUG] 02 二月 01:19:25.221 下午 DefaultQuartzScheduler_Worker-10 [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. Quartz1.8.5例子(十四)

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

  3. Quartz1.8.5例子(十一)

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

  4. Quartz1.8.5例子(十)

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

  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 ...

  10. Quartz1.8.5例子(四)

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

随机推荐

  1. svn 上传 过滤

    代码上传过程中发现.so文件不能上传,查了一下,发现是svn服务器要设置上传过滤:很多文件,会被过滤掉,不能正常上传.设置如下: 通过终端打开配置文件: open ~/.subversion/conf ...

  2. gist c code

    http://lear.inrialpes.fr/software Fisher kernel: http://vision.caltech.edu/~sbranson/code/index.html ...

  3. mybatis02 架构

    SqlMapConfig.xml(mybatis全局配置文件加载mybatis环境(数据源,事物,mapper.xml(配置sql语句),),类似于hibernate的全局配置文件,用于加载hiber ...

  4. locale------- linux字符集

    查看当前系统字符集 [root@server1 ~]# locale LANG=zh_CN.UTF-8LC_CTYPE="zh_CN.UTF-8"LC_NUMERIC=" ...

  5. WPF中将DataGrid导出Excel

    int number = 1; private void MenuItem_Click(object sender, RoutedEventArgs e) { #region string path ...

  6. PHP安全外延

    接下来,我们讲一下:php语言与Apache等中间.MySQL等数据库结合使用时所产生的一些安全问题. 1.文件解析漏洞分析 2.编码注入漏洞分析 3.is_numeric漏洞分析

  7. 在VS中关于MySQL的相关问题

    最近在vs上折腾mysql数据库 遇到了一些小问题,这里记录一下 问题一:数据源选择中没有mysql数据库的选项 解放方法: 1.安装MySql的VS插件(版本请下载最新版)mysql-for-vis ...

  8. QL查询案例:取得分组 TOP-N

    [转]SQL查询案例:取得分组 TOP-N CREATE TABLE TopnTest ( name     VARCHAR(10),   --姓名 procDate DATETIME,       ...

  9. web开发基础(同步更新中)

    1/Get与Post的区别 GET是我们都熟悉的.它用于请求网页文本.当你在浏览器输入harvard.edu,它会直接访问Harvard的web服务器,去GET /. 第二个最有名的是POST,它经常 ...

  10. python文件操作汇总

    1.创建文件 f = open(filename,'w+')