complete java program using quartz scheduler

Posted by Sudheep.Grandhe under Others on 11/7/2013 | Points: 10 | Views : 1612 | Status : [Member] | Replies : 10
how to write a complete java program to trigger that fires immediately, then repeats every 1 hour, forever

Best,
Sudheep.



Responses

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down

Refer
http://www.mkyong.com/java/quartz-scheduler-example/
http://oreilly.com/pub/a/java/archive/quartz.html?page=2
http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/TutorialLesson04
http://aspalliance.com/chapters/chapters/1847191525/OSWorkflow%20Sample%20Chapter.pdf

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SimpleTrigger example
Run very 30 seconds with a 1 second delay for the first time of execution.

package com.mkyong.common;

import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;

public class SimpleTriggerExample
{
public static void main( String[] args ) throws Exception
{
JobDetail job = new JobDetail();
job.setName("dummyJobName");
job.setJobClass(HelloJob.class);

//configure the scheduler time
SimpleTrigger trigger = new SimpleTrigger();
trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
trigger.setRepeatInterval(30000);

//schedule it
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);

}
}

http://nurkiewicz.blogspot.in/2012/04/quartz-scheduler-misfire-instructions.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link for scheduling for infinitely
http://nurkiewicz.blogspot.in/2012/04/quartz-scheduler-misfire-instructions.html

val trigger = newTrigger().
startAt(dateOf(9, 0, 0)).
withSchedule(
simpleSchedule().
withRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY ).
withIntervalInHours(1).
WithMisfireHandlingInstructionFireNow() //or other
).
build()


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.Grandhe on: 11/7/2013 [Member] Starter | Points: 25

Up
0
Down
thank u for your quick response

Best,
Sudheep.

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.Grandhe on: 11/7/2013 [Member] Starter | Points: 25

Up
0
Down
but i want the program to run every 60 minutes instead of 30 seconds

Best,
Sudheep.

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be change 30 seconds to 60 minutes as follows:
trigger.setRepeatInterval(3600000);

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/7/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Check the following example
Build a trigger that will fire at the top of the next hour, then repeat every 1 hours, forever :

trigger = newTrigger()
.withIdentity("trigger8") // because group is not specified, "trigger8" will be in the default group
.startAt(evenHourDate(null)) // get the next even-hour (minutes and seconds zero ("00:00"))
.withSchedule(simpleSchedule()
.withIntervalInHours(1)
.repeatForever())
// note that in this example, 'forJob(..)' is not called
// - which is valid if the trigger is passed to the scheduler along with the job
.build();

scheduler.scheduleJob(trigger, job);


Reference:
http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-05

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.Grandhe on: 11/8/2013 [Member] Starter | Points: 25

Up
0
Down
may i know where this "job.setJobClass(HelloJob.class);" is defined.?

Best,
Sudheep.

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
This link will give you complete sample program... ( contains HelloJob.class too)
http://www.mkyong.com/java/quartz-scheduler-example

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/14/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Click on "Mark As Answer " link if the above posts helped you

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Sudheep.Grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response