Quartz 1 – TutorialLesson1   Leave a comment


Before you can use the scheduler, it needs to be instantiated (who’d
have guessed?). To do this, you use a SchedulerFactory. Some users of
Quartz may keep an instance of a factory serialized in a JNDI store,
others may find it just as easy (or easier) to instantiate and use a
factory instance directly (such as in the example below).

Once a scheduler is instantiated, it can be started, placed in
stand-by mode, and shutdown. Note that once a scheduler is shutdown, it
cannot be restarted without being re-instantiated. Triggers do not fire
(jobs do not execute) until the scheduler has been started, nor while
it is in the paused state.

Here’s a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:

Using Quartz
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

Scheduler sched = schedFact.getScheduler();


JobDetail jobDetail = new JobDetail("myJob",

Trigger trigger = TriggerUtils.makeHourlyTrigger(); // fire every hour
trigger.setStartTime(TriggerUtils.getEvenHourDate(new Date())); // start on the next even hour

sched.scheduleJob(jobDetail, trigger);

As you can see, working with quartz is rather simple. In Lesson 2 we’ll give a quick overview of Jobs and Triggers, so that you can more fully understand this example.

Posted 2009年11月3日 by gw8310 in Computers and Internet


Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: