- 浏览: 984894 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
Quartz的使用:http://donald-draper.iteye.com/blog/2321886
Quartz的Scheduler初始化源码分析:http://donald-draper.iteye.com/blog/2322730
Quartz的job、触发器的暂停与恢复源码分析:http://donald-draper.iteye.com/blog/2322823
Quartz的Job存储,触发器、任务删除,源码分析:http://donald-draper.iteye.com/blog/2322725
Quartzs的job,trriger监听器源码分析:http://donald-draper.iteye.com/blog/2322863
Quartz 任务存储JobStoreTX 持久化之RDB:http://donald-draper.iteye.com/blog/2323297
Quartz 任务存储JobStoreTX 持久化之RDB-源码分析:http://donald-draper.iteye.com/blog/2323409
Quartz任务调度源码分析:http://donald-draper.iteye.com/blog/2323118
Spring与Quartz集成详解:http://donald-draper.iteye.com/blog/2323591
Spring与Quartz集成-源码分析:http://donald-draper.iteye.com/blog/2324132
一般获取Scheduler的方式
第一种:
第二种:
下面先来看看第一种到底做了些什么
//调度器仓库
//标准执行器实际上是包装了QuartzScheduler
//调度器
//QuartzScheduler的资源管理器
从StdSchedulerFactory的getDefaultScheduler方法可以看出与getScheduler相同
总结:
从以上代码分析中,看出StdSchedulerFactory获取执行器,首先从调度器仓库获取调度器,如果为空,则配置属性cfg,如果cfg为空则初始化属性文件,如果没有配置属性文件,则加载默认属性;然后初始化调度器(线程池,存储器,job,trriger监控器,JMX,及调度器仓库,如果存储器为JobStoreTX ,则初始化数据库信息);从返回的调度器来看实际上就是QuartzScheduler
Quartz的Scheduler初始化源码分析:http://donald-draper.iteye.com/blog/2322730
Quartz的job、触发器的暂停与恢复源码分析:http://donald-draper.iteye.com/blog/2322823
Quartz的Job存储,触发器、任务删除,源码分析:http://donald-draper.iteye.com/blog/2322725
Quartzs的job,trriger监听器源码分析:http://donald-draper.iteye.com/blog/2322863
Quartz 任务存储JobStoreTX 持久化之RDB:http://donald-draper.iteye.com/blog/2323297
Quartz 任务存储JobStoreTX 持久化之RDB-源码分析:http://donald-draper.iteye.com/blog/2323409
Quartz任务调度源码分析:http://donald-draper.iteye.com/blog/2323118
Spring与Quartz集成详解:http://donald-draper.iteye.com/blog/2323591
Spring与Quartz集成-源码分析:http://donald-draper.iteye.com/blog/2324132
一般获取Scheduler的方式
第一种:
SchedulerFactory schedulerFactory = new StdSchedulerFactory(); Scheduler cronScheduler = schedulerFactory.getScheduler();
第二种:
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
下面先来看看第一种到底做了些什么
public class StdSchedulerFactory implements SchedulerFactory { //获取调度器Scheduler public Scheduler getScheduler() throws SchedulerException { if(cfg == null) //初始化Quartz属性,线程池,线程数,线程优先级,job存储容器 initialize(); //获取调度器仓库单例 SchedulerRepository schedRep = SchedulerRepository.getInstance(); //根据调度器name,寻到对应的Scheduler Scheduler sched = schedRep.lookup(getSchedulerName()); if(sched != null) if(sched.isShutdown()) schedRep.remove(getSchedulerName()); else return sched; //初始化调度器 sched = instantiate(); return sched; } //从StdSchedulerFactory的getDefaultScheduler方法可以看出 //与getScheduler相同 public static Scheduler getDefaultScheduler() throws SchedulerException { StdSchedulerFactory fact = new StdSchedulerFactory(); return fact.getScheduler(); } //初始化Quartz属性,线程池,线程数,线程优先级,job存储容器配置 public void initialize() throws SchedulerException { String requestedFile; String propFileName; File propFile; Properties props; InputStream in; if(cfg != null) return; if(initException != null) throw initException; requestedFile = System.getProperty("org.quartz.properties"); propFileName = requestedFile == null ? "quartz.properties" : requestedFile; propFile = new File(propFileName); props = new Properties(); in = null; //如果propFile存在,则从文件系统,加载相应的属性文件 if(propFile.exists()) try { if(requestedFile != null) propSrc = (new StringBuilder()).append("specified file: '").append(requestedFile).append("'").toString(); else propSrc = "default file in current working dir: 'quartz.properties'"; in = new BufferedInputStream(new FileInputStream(propFileName)); props.load(in); } catch(IOException ioe) { initException = new SchedulerException((new StringBuilder()).append("Properties file: '").append(propFileName).append("' could not be read.").toString(), ioe); throw initException; } else //如果org.quartz.propertiess属性文件不为null,则从当前Thread的ClassLoader的Context加载相应的属性文件 if(requestedFile != null) { in = Thread.currentThread().getContextClassLoader().getResourceAsStream(requestedFile); if(in == null) { initException = new SchedulerException((new StringBuilder()).append("Properties file: '").append(requestedFile).append("' could not be found.").toString()); throw initException; } propSrc = (new StringBuilder()).append("specified file: '").append(requestedFile).append("' in the class resource path.").toString(); in = new BufferedInputStream(in); try { props.load(in); } catch(IOException ioe) { initException = new SchedulerException((new StringBuilder()).append("Properties file: '").append(requestedFile).append("' could not be read.").toString(), ioe); throw initException; } } else { propSrc = "default resource file in Quartz package: 'quartz.properties'"; ClassLoader cl = getClass().getClassLoader(); if(cl == null) cl = findClassloader(); if(cl == null) throw new SchedulerConfigException("Unable to find a class loader on the current thread or class."); in = cl.getResourceAsStream("quartz.properties"); if(in == null) in = cl.getResourceAsStream("/quartz.properties"); if(in == null) in = cl.getResourceAsStream("org/quartz/quartz.properties"); if(in == null) { initException = new SchedulerException("Default quartz.properties not found in class path"); throw initException; } try { props.load(in); } catch(IOException ioe) { initException = new SchedulerException("Resource properties file: 'org/quartz/quartz.properties' could not be read from the classpath.", ioe); throw initException; } } if(in != null) try { in.close(); } catch(IOException ignore) { } break MISSING_BLOCK_LABEL_502; Exception exception; exception; if(in != null) try { in.close(); } catch(IOException ignore) { } throw exception; initialize(overrideWithSysProps(props)); return; } //重载系统属性 private Properties overrideWithSysProps(Properties props) { Properties sysProps = null; try { sysProps = System.getProperties(); } catch(AccessControlException e) { getLog().warn("Skipping overriding quartz properties with System properties during initialization because of an AccessControlException. This is likely due to not having read/write access for java.util.PropertyPermission as required by java.lang.System.getProperties(). To resolve this warning, either add this permission to your policy file or use a non-default version of initialize().", e); } if(sysProps != null) props.putAll(sysProps); return props; } //初始化PropertiesParser public void initialize(Properties props) throws SchedulerException { if(propSrc == null) propSrc = "an externally provided properties instance."; cfg = new PropertiesParser(props); } //初始化Quartz属性,线程池,线程数,线程优先级,job存储容器 private Scheduler instantiate() throws SchedulerException { JobStore js;//job存储器 ThreadPool tp;// 线程池 QuartzScheduler qs; DBConnectionManager dbMgr;//数据库连接管理器 ThreadExecutor threadExecutor;//线程执行器 SchedulerRepository schedRep;//调度器仓库 boolean makeSchedulerThreadDaemon;//Scheduler调度线程方式前台,守候 boolean threadsInheritInitalizersClassLoader;//线程初始化继承属性 long batchTimeWindow; int maxBatchSize; if(cfg == null)//initialize(Properties props)已经初始化cfg initialize(); if(initException != null) throw initException; //初始化相关属性 schedRep = SchedulerRepository.getInstance(); schedName = cfg.getStringProperty("org.quartz.scheduler.instanceName", "QuartzScheduler"); threadName = cfg.getStringProperty("org.quartz.scheduler.threadName", (new StringBuilder()).append(schedName).append("_QuartzSchedulerThread").toString()); schedInstId = cfg.getStringProperty("org.quartz.scheduler.instanceId", "NON_CLUSTERED") String classLoadHelperClass = cfg.getStringProperty("org.quartz.scheduler.classLoadHelper.class", "org.quartz.simpl.CascadingClassLoadHelper"); String jobFactoryClass = cfg.getStringProperty("org.quartz.scheduler.jobFactory.class", null); batchTimeWindow = cfg.getLongProperty("org.quartz.scheduler.batchTriggerAcquisitionFireAheadTimeWindow", 0L); maxBatchSize = cfg.getIntProperty("org.quartz.scheduler.batchTriggerAcquisitionMaxCount", 1); jmxExport = cfg.getBooleanProperty("org.quartz.scheduler.jmx.export"); jmxObjectName = cfg.getStringProperty("org.quartz.scheduler.jmx.objectName"); boolean jmxProxy = cfg.getBooleanProperty("org.quartz.scheduler.jmx.proxy"); String jmxProxyClass = cfg.getStringProperty("org.quartz.scheduler.jmx.proxy.class"); loadHelper.initialize(); //初始化JMX Proxy if(jmxProxy) { if(autoId) schedInstId = "NON_CLUSTERED"; if(jmxProxyClass == null) throw new SchedulerConfigException("No JMX Proxy Scheduler class provided"); RemoteMBeanScheduler jmxScheduler = null; try { jmxScheduler = (RemoteMBeanScheduler)loadHelper.loadClass(jmxProxyClass).newInstance(); } if(jmxObjectName == null) jmxObjectName = QuartzSchedulerResources.generateJMXObjectName(schedName, schedInstId); jmxScheduler.setSchedulerObjectName(jmxObjectName); tProps = cfg.getPropertyGroup("org.quartz.scheduler.jmx.proxy", true); try { setBeanProps(jmxScheduler, tProps); } jmxScheduler.initialize(); schedRep.bind(jmxScheduler); return jmxScheduler; } jobFactory = null; //初始化jobFactory if(jobFactoryClass != null) { try { jobFactory = (jobFactory)loadHelper.loadClass(jobFactoryClass).newInstance(); } tProps = cfg.getPropertyGroup("org.quartz.scheduler.jobFactory", true); try { setBeanProps(jobFactory, tProps); } } //加载JobStore,org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore try { js = (JobStore)loadHelper.loadClass(jsClass).newInstance(); } //如果org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX ,配置数据库信息 String dsNames[] = cfg.getPropertyGroups("org.quartz.dataSource"); for(int i = 0; i < dsNames.length; i++) { PropertiesParser pp = new PropertiesParser(cfg.getPropertyGroup((new StringBuilder()).append("org.quartz.dataSource.").append(dsNames[i]).toString(), true)); String cpClass = pp.getStringProperty("connectionProvider.class", null); if(cpClass != null) { ConnectionProvider cp = null; try { cp = (ConnectionProvider)loadHelper.loadClass(cpClass).newInstance(); } try { pp.getUnderlyingProperties().remove("connectionProvider.class"); setBeanProps(cp, pp.getUnderlyingProperties()); cp.initialize(); } dbMgr = DBConnectionManager.getInstance(); dbMgr.addConnectionProvider(dsNames[i], cp); continue; } try { PoolingConnectionProvider cp = new PoolingConnectionProvider(pp.getUnderlyingProperties()); dbMgr = DBConnectionManager.getInstance(); dbMgr.addConnectionProvider(dsNames[i], cp); continue; } } //初始化插件 pluginNames = cfg.getPropertyGroups("org.quartz.plugin"); plugins = new SchedulerPlugin[pluginNames.length]; for(int i = 0; i < pluginNames.length; i++) { Properties pp = cfg.getPropertyGroup((new StringBuilder()).append("org.quartz.plugin.").append(pluginNames[i]).toString(), true); String plugInClass = pp.getProperty("class", null); if(plugInClass == null) { initException = new SchedulerException((new StringBuilder()).append("SchedulerPlugin class not specified for plugin '").append(pluginNames[i]).append("'").toString()); throw initException; } SchedulerPlugin plugin = null; try { plugin = (SchedulerPlugin)loadHelper.loadClass(plugInClass).newInstance(); } try { setBeanProps(plugin, pp); } plugins[i] = plugin; } //job监听器 String jobListenerNames[] = cfg.getPropertyGroups("org.quartz.jobListener"); jobListeners = new JobListener[jobListenerNames.length]; for(int i = 0; i < jobListenerNames.length; i++) { Properties lp = cfg.getPropertyGroup((new StringBuilder()).append("org.quartz.jobListener.").append(jobListenerNames[i]).toString(), true); String listenerClass = lp.getProperty("class", null); if(listenerClass == null) { initException = new SchedulerException((new StringBuilder()).append("JobListener class not specified for listener '").append(jobListenerNames[i]).append("'").toString()); throw initException; } JobListener listener = null; try { listener = (JobListener)loadHelper.loadClass(listenerClass).newInstance(); } try { Method nameSetter = null; try { nameSetter = listener.getClass().getMethod("setName", strArg); } if(nameSetter != null) nameSetter.invoke(listener, new Object[] { jobListenerNames[i] }); setBeanProps(listener, lp); } jobListeners[i] = listener; } //Trrige监听器 String triggerListenerNames[] = cfg.getPropertyGroups("org.quartz.triggerListener"); triggerListeners = new TriggerListener[triggerListenerNames.length]; for(int i = 0; i < triggerListenerNames.length; i++) { Properties lp = cfg.getPropertyGroup((new StringBuilder()).append("org.quartz.triggerListener.").append(triggerListenerNames[i]).toString(), true); String listenerClass = lp.getProperty("class", null); if(listenerClass == null) { initException = new SchedulerException((new StringBuilder()).append("TriggerListener class not specified for listener '").append(triggerListenerNames[i]).append("'").toString()); throw initException; } TriggerListener listener = null; try { listener = (TriggerListener)loadHelper.loadClass(listenerClass).newInstance(); } try { Method nameSetter = null; try { nameSetter = listener.getClass().getMethod("setName", strArg); } if(nameSetter != null) nameSetter.invoke(listener, new Object[] { triggerListenerNames[i] }); setBeanProps(listener, lp); } triggerListeners[i] = listener; } //初始化线程池执行类 String threadExecutorClass = cfg.getStringProperty("org.quartz.threadExecutor.class"); if(threadExecutorClass != null) { tProps = cfg.getPropertyGroup("org.quartz.threadExecutor", true); try { threadExecutor = (ThreadExecutor)loadHelper.loadClass(threadExecutorClass).newInstance(); log.info((new StringBuilder()).append("Using custom implementation for ThreadExecutor: ").append(threadExecutorClass).toString()); setBeanProps(threadExecutor, tProps); } } else { log.info("Using default implementation for ThreadExecutor"); threadExecutor = new DefaultThreadExecutor(); } Scheduler scheduler; //初始化job执行器 JobRunShellFactory jrsf = null; if(userTXLocation != null) UserTransactionHelper.setUserTxLocation(userTXLocation); if(wrapJobInTx) jrsf = new JTAJobRunShellFactory(); else jrsf = new JTAAnnotationAwareJobRunShellFactory(); if(autoId) try { schedInstId = "NON_CLUSTERED"; if(js.isClustered()) schedInstId = instanceIdGenerator.generateInstanceId(); } catch(Exception e) { getLog().error("Couldn't generate instance Id!", e); throw new IllegalStateException("Cannot run without an instance id."); } if(js.getClass().getName().startsWith("org.terracotta.quartz")) { try { String uuid = (String)js.getClass().getMethod("getUUID", new Class[0]).invoke(js, new Object[0]); if(schedInstId.equals("NON_CLUSTERED")) { schedInstId = (new StringBuilder()).append("TERRACOTTA_CLUSTERED,node=").append(uuid).toString(); if(jmxObjectName == null) jmxObjectName = QuartzSchedulerResources.generateJMXObjectName(schedName, schedInstId); } else if(jmxObjectName == null) jmxObjectName = QuartzSchedulerResources.generateJMXObjectName(schedName, (new StringBuilder()).append(schedInstId).append(",node=").append(uuid).toString()); } catch(Exception e) { throw new RuntimeException("Problem obtaining node id from TerracottaJobStore.", e); } if(null == cfg.getStringProperty("org.quartz.scheduler.jmx.export")) jmxExport = true; } if(js instanceof JobStoreSupport) { JobStoreSupport jjs = (JobStoreSupport)js; jjs.setDbRetryInterval(dbFailureRetry); if(threadsInheritInitalizersClassLoader) jjs.setThreadsInheritInitializersClassLoadContext(threadsInheritInitalizersClassLoader); jjs.setThreadExecutor(threadExecutor); } //QuartzScheduler资源管理器 QuartzSchedulerResources rsrcs = new QuartzSchedulerResources(); rsrcs.setName(schedName); rsrcs.setThreadName(threadName); rsrcs.setInstanceId(schedInstId); rsrcs.setJobRunShellFactory(jrsf); rsrcs.setMakeSchedulerThreadDaemon(makeSchedulerThreadDaemon); rsrcs.setThreadsInheritInitializersClassLoadContext(threadsInheritInitalizersClassLoader); rsrcs.setRunUpdateCheck(!skipUpdateCheck); rsrcs.setBatchTimeWindow(batchTimeWindow); rsrcs.setMaxBatchSize(maxBatchSize); rsrcs.setInterruptJobsOnShutdown(interruptJobsOnShutdown); rsrcs.setInterruptJobsOnShutdownWithWait(interruptJobsOnShutdownWithWait); rsrcs.setJMXExport(jmxExport); rsrcs.setJMXObjectName(jmxObjectName); if(managementRESTServiceEnabled) { ManagementRESTServiceConfiguration managementRESTServiceConfiguration = new ManagementRESTServiceConfiguration(); managementRESTServiceConfiguration.setBind(managementRESTServiceHostAndPort); managementRESTServiceConfiguration.setEnabled(managementRESTServiceEnabled); rsrcs.setManagementRESTServiceConfiguration(managementRESTServiceConfiguration); } if(rmiExport) { rsrcs.setRMIRegistryHost(rmiHost); rsrcs.setRMIRegistryPort(rmiPort); rsrcs.setRMIServerPort(rmiServerPort); rsrcs.setRMICreateRegistryStrategy(rmiCreateRegistry); rsrcs.setRMIBindName(rmiBindName); } SchedulerDetailsSetter.setDetails(tp, schedName, schedInstId); rsrcs.setThreadExecutor(threadExecutor); //线程池初始化 threadExecutor.initialize(); rsrcs.setThreadPool(tp); if((tp instanceof SimpleThreadPool) && threadsInheritInitalizersClassLoader) ((SimpleThreadPool)tp).setThreadsInheritContextClassLoaderOfInitializingThread(threadsInheritInitalizersClassLoader); tp.initialize(); tpInited = true; rsrcs.setJobStore(js); for(int i = 0; i < plugins.length; i++) rsrcs.addSchedulerPlugin(plugins[i]); //新建QuartzScheduler qs = new QuartzScheduler(rsrcs, idleWaitTime, dbFailureRetry); qsInited = true; //初始化scheduler scheduler = instantiate(rsrcs, qs); if(jobFactory != null) qs.setJobFactory(jobFactory); for(int i = 0; i < plugins.length; i++) plugins[i].initialize(pluginNames[i], scheduler, loadHelper); for(int i = 0; i < jobListeners.length; i++) qs.getListenerManager().addJobListener(jobListeners[i], EverythingMatcher.allJobs()); for(int i = 0; i < triggerListeners.length; i++) qs.getListenerManager().addTriggerListener(triggerListeners[i], EverythingMatcher.allTriggers()); Object key; String val; for(Iterator i$ = schedCtxtProps.keySet().iterator(); i$.hasNext(); scheduler.getContext().put((String)key, val)) { key = i$.next(); val = schedCtxtProps.getProperty((String)key); } js.setInstanceId(schedInstId); js.setInstanceName(schedName); js.setThreadPoolSize(tp.getPoolSize()); js.initialize(loadHelper, qs.getSchedulerSignaler()); jrsf.initialize(scheduler); qs.initialize(); getLog().info((new StringBuilder()).append("Quartz scheduler '").append(scheduler.getSchedulerName()).append("' initialized from ").append(propSrc).toString()); getLog().info((new StringBuilder()).append("Quartz scheduler version: ").append(qs.getVersion()).toString()); qs.addNoGCObject(schedRep); if(dbMgr != null) qs.addNoGCObject(dbMgr); //绑定scheduler到调度器仓库 schedRep.bind(scheduler); return scheduler;//实际为QuartzScheduler } //初始化Scheduler protected Scheduler instantiate(QuartzSchedulerResources rsrcs, QuartzScheduler qs) { Scheduler scheduler = new StdScheduler(qs); return scheduler; } //解析quartz.properties配置文件属性 private PropertiesParser cfg; }
//调度器仓库
public class SchedulerRepository { private SchedulerRepository() { schedulers = new HashMap(); } //获取调度器仓库单例 public static synchronized SchedulerRepository getInstance() { if(inst == null) inst = new SchedulerRepository(); return inst; } //添加调度器到仓库 public synchronized void bind(Scheduler sched) throws SchedulerException { if((Scheduler)schedulers.get(sched.getSchedulerName()) != null) { throw new SchedulerException((new StringBuilder()).append("Scheduler with name '").append(sched.getSchedulerName()).append("' already exists.").toString()); } else { schedulers.put(sched.getSchedulerName(), sched); return; } } public synchronized boolean remove(String schedName) { return schedulers.remove(schedName) != null; } //根据调度器name,寻到对应的Scheduler public synchronized Scheduler lookup(String schedName) { return (Scheduler)schedulers.get(schedName); } public synchronized Collection lookupAll() { return Collections.unmodifiableCollection(schedulers.values()); } private HashMap schedulers;//Hash<String,Scheduler> private static SchedulerRepository inst; }
//标准执行器实际上是包装了QuartzScheduler
public class StdScheduler implements Scheduler { public StdScheduler(QuartzScheduler sched) { this.sched = sched; } private QuartzScheduler sched; }
//调度器
public class QuartzScheduler implements RemotableQuartzScheduler { public QuartzScheduler(QuartzSchedulerResources resources, long idleWaitTime, long dbRetryInterval) throws SchedulerException { } private static String VERSION_MAJOR; private static String VERSION_MINOR; private static String VERSION_ITERATION; private QuartzSchedulerResources resources; private QuartzSchedulerThread schedThread; private ThreadGroup threadGroup; private SchedulerContext context; private ListenerManager listenerManager; private HashMap internalJobListeners; private HashMap internalTriggerListeners; private ArrayList internalSchedulerListeners; private JobFactory jobFactory; ExecutingJobsManager jobMgr; ErrorLogger errLogger; private SchedulerSignaler signaler; private Random random; private ArrayList holdToPreventGC; private boolean signalOnSchedulingChange; private volatile boolean closed; private volatile boolean shuttingDown; private boolean boundRemotely; private QuartzSchedulerMBean jmxBean; private Date initialStart; private final Timer updateTimer; private final Logger log = LoggerFactory.getLogger(getClass()); }
//QuartzScheduler的资源管理器
public class QuartzSchedulerResources { public static final String CREATE_REGISTRY_NEVER = "never"; public static final String CREATE_REGISTRY_ALWAYS = "always"; public static final String CREATE_REGISTRY_AS_NEEDED = "as_needed"; private String name; private String instanceId; private String threadName; private String rmiRegistryHost; private int rmiRegistryPort; private int rmiServerPort; private String rmiCreateRegistryStrategy; private ThreadPool threadPool; private JobStore jobStore; private JobRunShellFactory jobRunShellFactory; private List schedulerPlugins; private boolean makeSchedulerThreadDaemon; private boolean threadsInheritInitializersClassLoadContext; private String rmiBindName; private boolean jmxExport; private String jmxObjectName; private ManagementRESTServiceConfiguration managementRESTServiceConfiguration; private ThreadExecutor threadExecutor; private boolean runUpdateCheck; private long batchTimeWindow; private int maxBatchSize; private boolean interruptJobsOnShutdown; private boolean interruptJobsOnShutdownWithWait; }
从StdSchedulerFactory的getDefaultScheduler方法可以看出与getScheduler相同
总结:
从以上代码分析中,看出StdSchedulerFactory获取执行器,首先从调度器仓库获取调度器,如果为空,则配置属性cfg,如果cfg为空则初始化属性文件,如果没有配置属性文件,则加载默认属性;然后初始化调度器(线程池,存储器,job,trriger监控器,JMX,及调度器仓库,如果存储器为JobStoreTX ,则初始化数据库信息);从返回的调度器来看实际上就是QuartzScheduler
发表评论
-
TreeSet在Quartz任务调度过程中的作用
2017-08-24 23:43 736红黑树详解:http://www.cnblogs.com/sk ... -
Quartz使用与Spring集成系列教程
2016-10-26 09:48 502Quartz的使用:http://donald-draper. ... -
Spring与Quartz集成-源码分析
2016-09-13 11:50 2723在阅读以下文章之前,如果对Quartz任务调度不是很熟悉,请看 ... -
Spring与Quartz集成详解
2016-09-09 17:52 2824首先这个所有的依赖包就不需要多讲了,首先下载Quazrt发布包 ... -
Quartz 任务存储JobStoreTX 持久化之RDB-源码分析
2016-09-08 18:24 2330Quartz 任务存储JobStoreTX 持久化之RDB:h ... -
Quartz 任务存储JobStoreTX 持久化之RDB
2016-09-08 11:52 2836Quartz储存方式之JDBC JobStoreTX:http ... -
Quartz任务调度源码分析
2016-09-07 13:12 3575Quartz的使用:http://donald-draper. ... -
Quartz的job调度源码分析
2016-09-06 13:03 8Quartz的使用:http://donald ... -
Quartzs的job,trriger监听器源码分析
2016-09-06 11:15 1488Quartz的使用:http://donald-draper. ... -
Quartz的job、触发器的暂停与恢复源码分析
2016-09-06 09:01 5274Quartz的使用:http://donald-draper. ... -
Quartzs的job存储,触发器、job删除源码分析
2016-09-05 15:39 4575前言:unscheduleJob针对TriggerKey,而d ... -
Quartz的使用
2016-09-05 11:39 1793Quartz使用总结:http://www.cnblogs.c ...
相关推荐
1. **初始化Scheduler**:通过`SchedulerFactory`获取Scheduler实例。 2. **定义Job**:创建Job类并实现`execute()`方法。 3. **创建JobDetail**:配置Job的属性,如Job类和Group。 4. **创建Trigger**:根据需求...
Quartz.NET支持多种数据库,如MySQL、Oracle、SQL Server等,这些脚本有助于在不同的数据库系统中配置和初始化Quartz.NET。 3. `Quartz.build`:这可能是构建脚本,如MSBuild或NAnt,用于自动化构建和测试Quartz...
5. **错误和问题处理**:整合过程中可能会遇到的问题包括但不限于:库版本冲突、Scheduler 初始化失败、作业执行异常、线程安全问题等。解决这些问题通常需要检查依赖库的兼容性、正确配置 Quartz 配置文件以及确保 ...
6. **源码分析** - 深入研究Quartz的源码,有助于理解其内部工作原理,如JobStore的实现(内存、数据库等)、调度算法等,这有助于优化和定制自己的调度需求。 通过上述内容,我们可以构建一个基于Quartz的Web应用...
Quartz 源码分析 了解 Quartz 的内部工作机制可以帮助你更好地利用这个库。Quartz 的源码提供了丰富的注释,你可以查看 `org.quartz.impl.StdSchedulerFactory`、`org.quartz.Scheduler`、`org.quartz.Trigger` 和 ...
4. **启动Scheduler**:在Spring的初始化方法中启动Quartz Scheduler,使其开始监控并执行任务。 5. **使用Quartz API**:在需要的地方,如Service层,可以调用Quartz提供的API来触发或修改任务。 SSM框架结合...
- 初始化Scheduler并安排任务: ```java Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); scheduler.scheduleJob(job, trigger); scheduler.start(); ``` 4. **使用博客链接** 博文链接...
3. **代码实现**:在应用中,创建Scheduler实例,并调用`scheduler.initialize(config)`方法初始化,这里的config是根据配置文件生成的`Properties`对象。 4. **启动集群**:在多个服务器上部署相同的应用实例,...
Spring 提供的`SchedulerFactoryBean`使得初始化和管理 Quartz Scheduler 变得简单。此外,Spring 还可以通过`JobDetailBean`和`TriggerBean`来创建和配置 Quartz 对象。 例如,你可以创建一个`MyJob`类实现`org....
2. **SchedulerFactory**:使用`StdSchedulerFactory`从配置文件中初始化Scheduler实例。 3. **Scheduling**:通过`Scheduler`的`start()`方法启动调度。 三、Quartz的工作流程 1. **定义Job与Trigger**:创建...
5. **启动Scheduler**:在Spring应用启动时,Quartz Scheduler会自动初始化并开始执行任务。如果需要手动启动,可以获取`Scheduler`实例并调用`start()`方法。 现在,我们已经成功地在Spring 2.5应用中集成了Quartz...
- 分析 `SchedulerFactoryBean` 的初始化过程,理解如何启动 Quartz Scheduler。 - 查看 Job 和 Trigger 的实现,理解其执行逻辑。 7. **最佳实践**: - 使用 Spring 的 JobListener 和 TriggerListener 追踪...
通过源码分析,开发者可以自定义扩展 Quartz 功能,满足特定的业务需求。 5. **Spring 集成 Quartz**: Spring 框架提供了一套与 Quartz 集成的工具,使得在 Spring 应用中配置和管理 Quartz 调度变得更加简单。...
5. **启动Scheduler**:当Spring容器启动时,SchedulerFactoryBean会自动初始化并启动Quartz Scheduler。 **Quartz Job和Trigger** - **Job**:Quartz中的Job接口,代表一个可执行的任务。开发者需要实现这个接口,...
- **Spring整合代码**:了解Spring如何通过`SchedulerFactoryBean`与Quartz进行交互,包括初始化Scheduler,添加Job和Trigger,以及处理异常。 5. **实战案例** - **创建简单任务**:创建一个简单的Job,例如发送...
通过Spring的`SchedulerFactoryBean`,我们可以配置Scheduler,并在Spring容器启动时自动初始化。 5. **动态管理**: 源码中的增删改查功能,允许用户在运行时添加、删除、更新和查询定时任务。这通常涉及数据库操作...
在Spring的配置文件(如`applicationContext.xml`)中,你需要声明一个`SchedulerFactoryBean`来初始化Quartz调度器: ```xml <bean id="scheduler" class="org.springframework.scheduling.quartz....
5. **启动与管理**:QuartzDemo还会包含一个主程序或初始化脚本,用于启动Scheduler并注册Jobs和Triggers。此外,它可能还提供了一些API或界面,用于查看和管理正在运行的调度任务。 6. **监听器**:Quartz允许我们...
Quartz和Spring集成的一个重要方面是,Spring的`SchedulerFactoryBean`,它是Quartz调度器的Spring包装器,负责初始化和配置Quartz实例。通过`SchedulerFactoryBean`,我们可以设置Quartz的配置属性,例如数据库连接...
通过 Quartz API,这些 Job 可以被添加到 Scheduler 并关联相应的 Trigger,从而实现自动化调度。 由于没有具体代码内容,我们无法深入分析这两个 Job 的实现细节。但在实际开发中,开发者会根据需求定义 Job 类,...