/*
* 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. 理解CSS中的三种选择器>+~

    1. p~ul p和ul有相同的父元素,选择出p元素之后的所有ul元素,其中,p和ul不一定是紧随,但是必须有相同的父元素 E+F            相邻兄弟选择器.选择匹配F的元素,且该元素位于 ...

  2. TCP keepalive

      2. TCP keepalive overview In order to understand what TCP keepalive (which we will just call keepa ...

  3. mysql 交互式连接和非交互式连接

    交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端 mysql_real_connect() 函数介绍 函数原型描述: MYSQL *m ...

  4. is_numeric漏洞分析

    2014年,PHP中is_numeric函数十六进制绕过漏洞引发了一次安全问题 接下来,我们来分析一下这个漏洞的原理 函数介绍: is_numeric — 检测变量是否为数字或数字字符串. 函数原型: ...

  5. 禁止输出重定向(>)覆盖已存在文件(防止误操作)

    在输出重定向中,>表示重定向并覆盖已有文件内容,为了防止误操作,覆盖重要的内容,可以使用如下命令: set -C 这样输出重定向到一个已有文件就会提示: cannot overwrite exi ...

  6. Asp.net简单三层+Sqllite 增删改查

    新建项目à新建一个空白解决方案 在Model新建一个实体类 using System; using System.Collections.Generic; using System.Linq; usi ...

  7. [Mime] MimeHeaders--MimeHeader帮助类 (转载)

    点击下载 MimeHeaders.rar 这个类是关于Mime的Headers类看下面代码吧 /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 // ...

  8. 用于做 Android 屏幕自适应的文章资源

    Android Developer : (1) https://developer.android.com/training/multiscreen/index.html (2) https://de ...

  9. 浅谈.net中的params关键字

    先举个例子: 代码如下: class Program { static void Main(string[] args) { Console.WriteLine(Sum(1)); Console.Wr ...

  10. QVW中实现日期区间的选择功能!

    QV在日期的选择上不是很灵活,日期区段的选择可以在列表框中直接用鼠标拖拉区段,如果跨周期比较长了还是不是很方便啦. 下面介绍的方式是完全实现了起始日期的选择功能. 注:日期这个字段在抽取的时候一定要格 ...