[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Shutdown of scheduler instance doesnot have any impact on jobs running  XML
Forum Index -> Quartz
Author Message
aspd

journeyman

Joined: 04/14/2010 05:57:01
Messages: 18
Offline

Background :
---------------
Version quartz-1.7.3
job store : org.quartz.impl.jdbcjobstore.JobStoreTX
database: mysql 5.0
IDE : eclipse


I have created three different standalone java classes.
1. Start Scheduler
2. Create a Cron Trigger
3. Shutdown scheduler.

I executed them in sequence.

But I found that the trigger was continuously executing the jobs even after I have executed the shutdown() method

The code fragments are as follows:

1. Start Scheduler
Code:
 
         // Initiate a Schedule Factory
         SchedulerFactory schedulerFactory = new StdSchedulerFactory();
         // Retrieve a scheduler from schedule factory
         Scheduler scheduler = schedulerFactory.getScheduler();
         
                 
         // start the scheduler
         scheduler.start();
 



2. Create a Cron Trigger
Code:
  // Initiate a Schedule Factory
         SchedulerFactory schedulerFactory = new StdSchedulerFactory();
         // Retrieve a scheduler from schedule factory
         Scheduler scheduler = schedulerFactory.getScheduler();
         
         // current time
         long ctime = System.currentTimeMillis(); 
         
         // Initiate JobDetail with job name, job group, and executable job class
         JobDetail jobDetail = new JobDetail("jobDetail2", "jobDetailGroup2", SimpleQuartzJob.class);
         // Initiate CronTrigger with its name and group name
         
         CronTrigger cronTrigger = new CronTrigger("cronTrigger", "triggerGroup2");
         try {
             // setup CronExpression
             CronExpression cexp = new CronExpression("0/5 * * * * ?");
             // Assign the CronExpression to CronTrigger
             cronTrigger.setCronExpression(cexp);
         } catch (Exception e) {
             e.printStackTrace();
         }
         // schedule a job with JobDetail and Trigger
         scheduler.scheduleJob(jobDetail, cronTrigger);
 
 


3. Shutdown scheduler.
Code:
  // Initiate a Schedule Factory
         SchedulerFactory schedulerFactory = new StdSchedulerFactory();
         // Retrieve a scheduler from schedule factory
         Scheduler scheduler = schedulerFactory.getScheduler();
         
                 
         // shut down the scheduler
         scheduler.shutdown();
 
 

jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


My best guess is that you're getting a handle to a different scheduler each time you do factory.getScheduler().

I suggest you add code to print the scheduler's memory address in each case, and confirm whether they are the same/different.


aspd

journeyman

Joined: 04/14/2010 05:57:01
Messages: 18
Offline

Thanks for your reply

I will give you the details that you needed, But would you please clarify me in the following regard.

As per our current design we need to have two applications that will use the Quartz scheduler.

1. A stand-alone java Scheduler application. Primarily intended for scheduler start-up and shutdown.

2. A web application that allows the user to create and Modify Cron triggers .

Please make note that in this case both the stand alone scheduler application and the web app are refering the same Job store.

Will there be any possibility to refer same scheduler from two different application.

But in our design both the applications share the same JVM.
QrtzHelp

journeyman

Joined: 01/16/2010 09:44:00
Messages: 37
Offline


The applications may share the same JVM, but they likely have different class loader space, and hence the Quartz instances each obtains won't be the same instances.


You can have the two apps share the same JobStore database by pointing their configs at the same database. BUT you must realize that this lets them share data, but they are distinct schedulers. Hence you must opt for one of the following setups:

option 1- Turn on the "isClustered=true" property for the jobstore. And then the jobs will execute within both schedulers (whichever gets around to executing it first).

option 2- Do not turn on clustering, but only call scheduler.start() on the scheduler in the application where you want the jobs to execute. The other application's scheduler (without start() called on it) can still store (schedule) and retrieve jobs, etc. it just won't execute any.
aspd

journeyman

Joined: 04/14/2010 05:57:01
Messages: 18
Offline

Thanks QrtzHelp
Thats seems a Perfect solution for my problem.

I am more focused on the second approach you have suggested i.e without clustering.

In my case I am not going to start ( scheduler.start() ) the scheduler in anycase from the application that updates are creates the Cron triggers.

I will start/shutdown it from the standalone scheduler application alone alone.

But I am bit confused by this
Never fire-up a non-clustered instance against the same set of tables that any other instance is running against. You may get serious data corruption, and will definitely experience eratic behavior. 


Reference : http://www.quartz-scheduler.org/docs/configuration/ConfigJDBCJobStoreClustering.html

Also would you please escalate the trade off of using the clustering, if any.



QrtzHelp

journeyman

Joined: 01/16/2010 09:44:00
Messages: 37
Offline


"fire-up" in that quoted sentence means start(). Perhaps that should be made more explicit.



Clustering gives you High Availability (if the quartz instances are in on different machines). It also brings scale, in that the jobs can execute on more machines - which may be important if your jobs use a lot of system resources.
aspd

journeyman

Joined: 04/14/2010 05:57:01
Messages: 18
Offline

Clustering seems to be a desirable feature as well.

So will It be better for me to opt for clustering (since more scalable). Rather than sticking on to the non-clustered.

The main reason is clustering allows the the second application ( the web application in my case) to start the scheduler and stop. Which is a desirable feature which would become a requirement in the near future.

In that case if I start/stop a single cluster instance, will it affect the whole scheduling, or only the current instance that I have stopped. It would be undesirable if it affects only one instance alone, bcoz we wont have a firm control over the over-all scheduling.


jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


start() and shutdown() only operate on the local instance.

Unless you use the RMI or JMX features to control a remote instance.
aspd

journeyman

Joined: 04/14/2010 05:57:01
Messages: 18
Offline

Thanks jhouse,
Do you mean the local instance in the sense that only one instance or the whole instanses.

As I have already mentioned that in our current application we will have all the instances (in case clustered ) will be running under the same JVM.

Currently we don't have any plans for remote instances (RMI ).
fusion

journeyman

Joined: 04/14/2010 22:39:54
Messages: 12
Offline

I have the similar requirement,

One application uses the clustered quartz, jobstore.

In another standalone, i need to get the notification of job completion.

How do i write the standalone code for job or trigger listener ?

any sample for the standalone would be of great help.
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


The events only go to the node that the action (e.g. job completion) occurred on.


You'll have to create a listener in the application it executes in, and have that listener pass a signal/data to the other application through whatever means you wish (rmi, database entries, socket connection, http post, etc.).
rajup3

neo

Joined: 02/11/2011 02:06:48
Messages: 8
Location: Pune
Offline

Hi All,

I have a similar requirement,

Using latest Quartz version 1.8.4 with Weblogic 11 g server and MS SQL.

Any solution is available in this release for events (Start/Stand-by/Shutdown) notification to all instances in a cluster?

If no, please suggest the best practice for the above env.?

Thanks in advance.
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team