Thread pool parsing for quartz

Source: Internet
Author: User

"Org.quartz.core related class Diagram"

You can see that the core class is Quartzscheduler

"Quartzscheduler Constructor"

 PublicQuartzscheduler (quartzschedulerresources Resources,LongIdlewaittime, @DeprecatedLongdbretryinterval)throwsschedulerexception { This. resources =resources; if(Resources.getjobstore ()instanceofJoblistener)    {Addinternaljoblistener (Joblistener) Resources.getjobstore ()); }    this.schedthread = new Quartzschedulerthread (this, resources);    Threadexecutor schedthreadexecutor = Resources.getthreadexecutor ();    Schedthreadexecutor.execute (This.schedthread); if(Idlewaittime > 0) {         This. Schedthread.setidlewaittime (Idlewaittime); } jobmgr=NewExecutingjobsmanager ();    Addinternaljoblistener (jobmgr); Errlogger=NewErrorlogger ();    Addinternalschedulerlistener (Errlogger); Signaler=NewSchedulersignalerimpl ( This, This. Schedthread); if(Shouldrunupdatecheck ()) Updatetimer=Scheduleupdatecheck (); ElseUpdatetimer=NULL; GetLog (). info ("Quartz Scheduler v." + getversion () + "created.");}

This creates a quartzschedulerthread and runs in Threadexecutor (the default defaultthreadexecutor). Threadexecutor here is not our concern, continue to see the quartzschedulerthread of the Run method.

"Quartzschedulerthread#run ()"

The Run method is long and the effect is to find out which job to run and then execute it in the thread pool according to trigger. Here is the code snippet for the Run method:

Jobrunshell Shell =NULL;Try{Shell=qsrsrcs.getjobrunshellfactory (). Createjobrunshell (Bndle); Shell.initialize (QS);} Catch(schedulerexception se) {qsrsrcs.getjobstore (). Triggeredjobcomplete (Triggers.get (i), Bndle.getjobdetail (),    COMPLETEDEXECUTIONINSTRUCTION.SET_ALL_JOB_TRIGGERS_ERROR); Continue;}if(Qsrsrcs.getthreadpool (). Runinthread (Shell)==false) {    //This case should never happen, as it is indicative of the//Scheduler being shutdown or a bug in the thread pool or//a thread pool being used Concurrently-which the docs//say do ...GetLog (). Error ("Threadpool.runinthread () return false!"); Qsrsrcs.getjobstore (). Triggeredjobcomplete (Triggers.get (i), Bndle.getjobdetail (), Completedexecutioninstruction.set_all_job_triggers_error);}

The threadpool here must implement the Org.quartz.spi.ThreadPool interface.

"ThreadPool Implementation Class"

The default implementation class for ThreadPool is Org.quartz.simpl.SimpleThreadPool.

String Tpclass = Cfg.getstringproperty (Prop_thread_pool_class, Simplethreadpool.  Class. GetName ());

(from Org.quartz.impl.stdschedulerfactory#instantiate ())

This thread pool is very simple and has no blockingqueue:

Private New Linkedlist<workerthread>();//Simplethreadpool member privatenew linkedlist< Workerthread> (); Simplethreadpool Members

If integrated with spring, Using Org.springframework.scheduling.quartz.SchedulerFactoryBean and configuring the Taskexecutor (Implementation class for Java.util.concurrent.Executor), the ORG.S Pringframework.scheduling.quartz.LocalTaskExecutorThreadPool.

if (thisnull) {    mergedprops.setproperty (Stdschedulerfactory.prop_thread_pool_class,            Localtaskexecutorthreadpool. class . GetName ());}

(from Org.springframework.scheduling.quartz.schedulerfactorybean#initschedulerfactory)

You can also customize the implementation class and configure the Org.quartz.threadPool.class parameter for quartzproperties.

Thread pool parsing for quartz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.