溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

spring boot + quartz集群搭建的完整步驟

發(fā)布時(shí)間:2020-10-01 05:51:35 來源:腳本之家 閱讀:258 作者:vincent_ren 欄目:編程語言

quartz集群能力:

  • quartz集群分為水平集群和垂直集群,水平集群即將定時(shí)任務(wù)節(jié)點(diǎn)部署在不同的服務(wù)器,水平集群最大的問題就是時(shí)鐘同步問題,
    quartz集群強(qiáng)烈要求時(shí)鐘同步,若時(shí)鐘不能同步,則會導(dǎo)致集群中各個節(jié)點(diǎn)狀態(tài)紊亂,造成不可預(yù)知的后果,請自行搜索服務(wù)器時(shí)鐘同步,
    若能保證時(shí)鐘同步,水平集群能保證服務(wù)的可靠性,其中一個節(jié)點(diǎn)掛掉或其中一個服務(wù)器宕機(jī),其他節(jié)點(diǎn)依然正常服務(wù);垂直集群則是集群各節(jié)點(diǎn)部署在同一臺服務(wù)器,
    時(shí)鐘同步自然不是問題,但存在單點(diǎn)故障問題,服務(wù)器宕機(jī)會嚴(yán)重影響服務(wù)的可用性。因此,要結(jié)合實(shí)際情況來考慮集群方案
  • 由于集群中強(qiáng)烈要求時(shí)鐘同步,因此不管是垂直集群還是水平集群,本地開發(fā)決不能連接線上環(huán)境(本地也是集群模式),這樣的話勢必會破壞集群,但本地若是非集群模式,
    則可以依情況來連接線上環(huán)境。
  • quartz集群和redis這樣的集群實(shí)現(xiàn)方式不一樣,redis集群需要節(jié)點(diǎn)之間通信,各節(jié)點(diǎn)需要知道其他節(jié)點(diǎn)的狀況,而quartz集群的實(shí)現(xiàn)
    方式在于11張表,集群節(jié)點(diǎn)相互之間不通信,而是通過定時(shí)任務(wù)持久化加鎖的方式來實(shí)現(xiàn)集群。
  • 破壞集群后果一般是死鎖或者狀態(tài)紊亂每個節(jié)點(diǎn)都不可用或其中某些節(jié)點(diǎn)能用部分或全部的定時(shí)任務(wù)

以上是個人的一些見解,下面開始本文的正文,本文主要介紹了關(guān)于spring boot + quartz集群搭建的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。

步驟如下:

spring boot bean配置:

@Configuration
public class QuartzConfig {
 @Value("${quartz.scheduler.instanceName}")
 private String quartzInstanceName;
  
 @Value("${org.quartz.dataSource.myDS.driver}")
 private String myDSDriver;
  
 @Value("${org.quartz.dataSource.myDS.URL}")
 private String myDSURL;
  
 @Value("${org.quartz.dataSource.myDS.user}")
 private String myDSUser;
  
 @Value("${org.quartz.dataSource.myDS.password}")
 private String myDSPassword;
  
 @Value("${org.quartz.dataSource.myDS.maxConnections}")
 private String myDSMaxConnections;
  
  
 /**
  * 設(shè)置屬性
  * @return
  * @throws IOException
  */
 private Properties quartzProperties() throws IOException {
  Properties prop = new Properties();
  prop.put("quartz.scheduler.instanceName", quartzInstanceName);
  prop.put("org.quartz.scheduler.instanceId", "AUTO");
  prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
  prop.put("org.quartz.scheduler.jmx.export", "true");
   
  prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
  prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.StdJDBCDelegate");
  prop.put("org.quartz.jobStore.dataSource", "quartzDataSource");
  prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
  prop.put("org.quartz.jobStore.isClustered", "true");
   
  prop.put("org.quartz.jobStore.clusterCheckinInterval", "20000");
  prop.put("org.quartz.jobStore.dataSource", "myDS");
  prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
  prop.put("org.quartz.jobStore.misfireThreshold", "120000");
  prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
  prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS WHERE LOCK_NAME = ? FOR UPDATE");
   
  prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
  prop.put("org.quartz.threadPool.threadCount", "10");
  prop.put("org.quartz.threadPool.threadPriority", "5");
  prop.put("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true");
   
  prop.put("org.quartz.dataSource.myDS.driver", myDSDriver);
  prop.put("org.quartz.dataSource.myDS.URL", myDSURL);
  prop.put("org.quartz.dataSource.myDS.user", myDSUser);
  prop.put("org.quartz.dataSource.myDS.password", myDSPassword);
  System.out.println("myDSMaxConnections:" + myDSMaxConnections);
  prop.put("org.quartz.dataSource.myDS.maxConnections", myDSMaxConnections);
   
  prop.put("org.quartz.plugin.triggHistory.class", "org.quartz.plugins.history.LoggingJobHistoryPlugin");
  prop.put("org.quartz.plugin.shutdownhook.class", "org.quartz.plugins.management.ShutdownHookPlugin");
  prop.put("org.quartz.plugin.shutdownhook.cleanShutdown", "true");
  return prop;
 }
  
 @Bean 
 public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("dialogJobTrigger") Trigger cronJobTrigger) throws IOException { 
  SchedulerFactoryBean factory = new SchedulerFactoryBean(); 
  // this allows to update triggers in DB when updating settings in config file: 
  //用于quartz集群,QuartzScheduler 啟動時(shí)更新己存在的Job,這樣就不用每次修改targetObject后刪除qrtz_job_details表對應(yīng)記錄了 
  factory.setOverwriteExistingJobs(true); 
  //用于quartz集群,加載quartz數(shù)據(jù)源 
  //factory.setDataSource(dataSource); 
  //QuartzScheduler 延時(shí)啟動,應(yīng)用啟動完10秒后 QuartzScheduler 再啟動 
  factory.setStartupDelay(10);
  //用于quartz集群,加載quartz數(shù)據(jù)源配置 
  factory.setQuartzProperties(quartzProperties());
  factory.setAutoStartup(true);
  factory.setApplicationContextSchedulerContextKey("applicationContext");
  //注冊觸發(fā)器 
  factory.setTriggers(cronJobTrigger);<br data-filtered="filtered">     //直接使用配置文件
//  factory.setConfigLocation(new FileSystemResource(this.getClass().getResource("/quartz.properties").getPath()));
  return factory; 
 }
  
  
 /**
  * 加載job
  * @return
  */
 @Bean 
 public JobDetailFactoryBean updateDialogStatusJobDetail() { 
  return createJobDetail(InvokingJobDetailDetailFactory.class, "updateDialogStatusGroup", "dialogJob"); 
 } 
 
 /**
  * 加載觸發(fā)器
  * @param jobDetail
  * @return
  */
 @Bean(name = "dialogJobTrigger") 
 public CronTriggerFactoryBean dialogStatusJobTrigger(@Qualifier("updateDialogStatusJobDetail") JobDetail jobDetail) { 
  return dialogStatusTrigger(jobDetail, "0 0 0/1 * * ?"); 
 } 
 
 /**
  * 創(chuàng)建job工廠
  * @param jobClass
  * @param groupName
  * @param targetObject
  * @return
  */
 private static JobDetailFactoryBean createJobDetail(Class<?> jobClass, String groupName, String targetObject) { 
  JobDetailFactoryBean factoryBean = new JobDetailFactoryBean(); 
  factoryBean.setJobClass(jobClass); 
  factoryBean.setDurability(true); 
  factoryBean.setRequestsRecovery(true);
  factoryBean.setGroup(groupName);
  Map<String, String> map = new HashMap<>();
  map.put("targetObject", targetObject);
  map.put("targetMethod", "execute");
  factoryBean.setJobDataAsMap(map);
  return factoryBean; 
 } 
 
 /**
  * 創(chuàng)建觸發(fā)器工廠
  * @param jobDetail
  * @param cronExpression
  * @return
  */
 private static CronTriggerFactoryBean dialogStatusTrigger(JobDetail jobDetail, String cronExpression) { 
  CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean(); 
  factoryBean.setJobDetail(jobDetail);
  factoryBean.setCronExpression (cronExpression);
  return factoryBean; 
 } 
}

InvokingJobDetailDetailFactory對象:

public class InvokingJobDetailDetailFactory extends QuartzJobBean{
 // 計(jì)劃任務(wù)所在類 
 private String targetObject;
 // 具體需要執(zhí)行的計(jì)劃任務(wù) 
 private String targetMethod;
 private ApplicationContext ctx;
 @Override
 protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  try {
   Object otargetObject = ctx.getBean(targetObject);
   Method m = null; 
   try { 
    m = otargetObject.getClass().getMethod(targetMethod); 
    m.invoke(otargetObject); 
   } catch (SecurityException e) { 
    e.printStackTrace(); 
   } catch (NoSuchMethodException e) { 
    e.printStackTrace(); 
   } 
  } catch (Exception e) { 
   throw new JobExecutionException(e); 
  }
 }
 
 public void setApplicationContext(ApplicationContext applicationContext) { 
  this.ctx = applicationContext; 
 } 
 
 public void setTargetObject(String targetObject) { 
  this.targetObject = targetObject; 
 } 
 
 public void setTargetMethod(String targetMethod) { 
  this.targetMethod = targetMethod; 
 }
}

備注:set方法不能少,setApplicationContext中的applicationContext與factory.setApplicationContextSchedulerContextKey("applicationContext")填入的值有關(guān),其原理由InvokingJobDetailDetailFactory父類中的BeanWrapper實(shí)現(xiàn)。

sql腳本:--

<em id="__mceDel">-- 表的結(jié)構(gòu) `qrtz_blob_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_blob_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `BLOB_DATA` blob
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_calendars`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_calendars` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `CALENDAR_NAME` varchar(120) NOT NULL,
 `CALENDAR` blob NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_cron_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_cron_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `CRON_EXPRESSION` varchar(120) NOT NULL,
 `TIME_ZONE_ID` varchar(80) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_fired_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_fired_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `ENTRY_ID` varchar(95) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `INSTANCE_NAME` varchar(120) NOT NULL,
 `FIRED_TIME` bigint(13) NOT NULL,
 `SCHED_TIME` bigint(13) NOT NULL,
 `PRIORITY` int(11) NOT NULL,
 `STATE` varchar(16) NOT NULL,
 `JOB_NAME` varchar(120) DEFAULT NULL,
 `JOB_GROUP` varchar(120) DEFAULT NULL,
 `IS_NONCONCURRENT` varchar(1) DEFAULT NULL,
 `REQUESTS_RECOVERY` varchar(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_job_details`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_job_details` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `JOB_NAME` varchar(120) NOT NULL,
 `JOB_GROUP` varchar(120) NOT NULL,
 `DESCRIPTION` varchar(250) DEFAULT NULL,
 `JOB_CLASS_NAME` varchar(250) NOT NULL,
 `IS_DURABLE` varchar(1) NOT NULL,
 `IS_NONCONCURRENT` varchar(1) NOT NULL,
 `IS_UPDATE_DATA` varchar(1) NOT NULL,
 `REQUESTS_RECOVERY` varchar(1) NOT NULL,
 `JOB_DATA` blob
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_locks`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_locks` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `LOCK_NAME` varchar(40) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_paused_trigger_grps`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_paused_trigger_grps` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_scheduler_state`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_scheduler_state` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `INSTANCE_NAME` varchar(120) NOT NULL,
 `LAST_CHECKIN_TIME` bigint(13) NOT NULL,
 `CHECKIN_INTERVAL` bigint(13) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_simple_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_simple_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `REPEAT_COUNT` bigint(7) NOT NULL,
 `REPEAT_INTERVAL` bigint(12) NOT NULL,
 `TIMES_TRIGGERED` bigint(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_simprop_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_simprop_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `STR_PROP_1` varchar(512) DEFAULT NULL,
 `STR_PROP_2` varchar(512) DEFAULT NULL,
 `STR_PROP_3` varchar(512) DEFAULT NULL,
 `INT_PROP_1` int(11) DEFAULT NULL,
 `INT_PROP_2` int(11) DEFAULT NULL,
 `LONG_PROP_1` bigint(20) DEFAULT NULL,
 `LONG_PROP_2` bigint(20) DEFAULT NULL,
 `DEC_PROP_1` decimal(13,4) DEFAULT NULL,
 `DEC_PROP_2` decimal(13,4) DEFAULT NULL,
 `BOOL_PROP_1` varchar(1) DEFAULT NULL,
 `BOOL_PROP_2` varchar(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-- --------------------------------------------------------
 
--
-- 表的結(jié)構(gòu) `qrtz_triggers`
--
 
CREATE TABLE IF NOT EXISTS `qrtz_triggers` (
 `SCHED_NAME` varchar(120) NOT NULL,
 `TRIGGER_NAME` varchar(120) NOT NULL,
 `TRIGGER_GROUP` varchar(120) NOT NULL,
 `JOB_NAME` varchar(120) NOT NULL,
 `JOB_GROUP` varchar(120) NOT NULL,
 `DESCRIPTION` varchar(250) DEFAULT NULL,
 `NEXT_FIRE_TIME` bigint(13) DEFAULT NULL,
 `PREV_FIRE_TIME` bigint(13) DEFAULT NULL,
 `PRIORITY` int(11) DEFAULT NULL,
 `TRIGGER_STATE` varchar(16) NOT NULL,
 `TRIGGER_TYPE` varchar(8) NOT NULL,
 `START_TIME` bigint(13) NOT NULL,
 `END_TIME` bigint(13) DEFAULT NULL,
 `CALENDAR_NAME` varchar(200) DEFAULT NULL,
 `MISFIRE_INSTR` smallint(2) DEFAULT NULL,
 `JOB_DATA` blob
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--
-- Indexes for dumped tables
--
 
--
-- Indexes for table `qrtz_blob_triggers`
--
ALTER TABLE `qrtz_blob_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`),
 ADD KEY `SCHED_NAME` (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_calendars`
--
ALTER TABLE `qrtz_calendars`
 ADD PRIMARY KEY (`SCHED_NAME`,`CALENDAR_NAME`);
 
--
-- Indexes for table `qrtz_cron_triggers`
--
ALTER TABLE `qrtz_cron_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_fired_triggers`
--
ALTER TABLE `qrtz_fired_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`ENTRY_ID`),
 ADD KEY `IDX_QRTZ_FT_TRIG_INST_NAME` (`SCHED_NAME`,`INSTANCE_NAME`),
 ADD KEY `IDX_QRTZ_FT_INST_JOB_REQ_RCVRY` (`SCHED_NAME`,`INSTANCE_NAME`,`REQUESTS_RECOVERY`),
 ADD KEY `IDX_QRTZ_FT_J_G` (`SCHED_NAME`,`JOB_NAME`,`JOB_GROUP`),
 ADD KEY `IDX_QRTZ_FT_JG` (`SCHED_NAME`,`JOB_GROUP`),
 ADD KEY `IDX_QRTZ_FT_T_G` (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`),
 ADD KEY `IDX_QRTZ_FT_TG` (`SCHED_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_job_details`
--
ALTER TABLE `qrtz_job_details`
 ADD PRIMARY KEY (`SCHED_NAME`,`JOB_NAME`,`JOB_GROUP`),
 ADD KEY `IDX_QRTZ_J_REQ_RECOVERY` (`SCHED_NAME`,`REQUESTS_RECOVERY`),
 ADD KEY `IDX_QRTZ_J_GRP` (`SCHED_NAME`,`JOB_GROUP`);
 
--
-- Indexes for table `qrtz_locks`
--
ALTER TABLE `qrtz_locks`
 ADD PRIMARY KEY (`SCHED_NAME`,`LOCK_NAME`);
 
--
-- Indexes for table `qrtz_paused_trigger_grps`
--
ALTER TABLE `qrtz_paused_trigger_grps`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_scheduler_state`
--
ALTER TABLE `qrtz_scheduler_state`
 ADD PRIMARY KEY (`SCHED_NAME`,`INSTANCE_NAME`);
 
--
-- Indexes for table `qrtz_simple_triggers`
--
ALTER TABLE `qrtz_simple_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_simprop_triggers`
--
ALTER TABLE `qrtz_simprop_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`);
 
--
-- Indexes for table `qrtz_triggers`
--
ALTER TABLE `qrtz_triggers`
 ADD PRIMARY KEY (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`),
 ADD KEY `IDX_QRTZ_T_J` (`SCHED_NAME`,`JOB_NAME`,`JOB_GROUP`),
 ADD KEY `IDX_QRTZ_T_JG` (`SCHED_NAME`,`JOB_GROUP`),
 ADD KEY `IDX_QRTZ_T_C` (`SCHED_NAME`,`CALENDAR_NAME`(191)),
 ADD KEY `IDX_QRTZ_T_G` (`SCHED_NAME`,`TRIGGER_GROUP`),
 ADD KEY `IDX_QRTZ_T_STATE` (`SCHED_NAME`,`TRIGGER_STATE`),
 ADD KEY `IDX_QRTZ_T_N_STATE` (`SCHED_NAME`,`TRIGGER_NAME`,`TRIGGER_GROUP`,`TRIGGER_STATE`),
 ADD KEY `IDX_QRTZ_T_N_G_STATE` (`SCHED_NAME`,`TRIGGER_GROUP`,`TRIGGER_STATE`),
 ADD KEY `IDX_QRTZ_T_NEXT_FIRE_TIME` (`SCHED_NAME`,`NEXT_FIRE_TIME`),
 ADD KEY `IDX_QRTZ_T_NFT_ST` (`SCHED_NAME`,`TRIGGER_STATE`,`NEXT_FIRE_TIME`),
 ADD KEY `IDX_QRTZ_T_NFT_MISFIRE` (`SCHED_NAME`,`MISFIRE_INSTR`,`NEXT_FIRE_TIME`),
 ADD KEY `IDX_QRTZ_T_NFT_ST_MISFIRE` (`SCHED_NAME`,`MISFIRE_INSTR`,`NEXT_FIRE_TIME`,`TRIGGER_STATE`),
 ADD KEY `IDX_QRTZ_T_NFT_ST_MISFIRE_GRP` (`SCHED_NAME`,`MISFIRE_INSTR`,`NEXT_FIRE_TIME`,`TRIGGER_GROUP`,`TRIGGER_STATE`);
 
--
-- 限制導(dǎo)出的表
--
 
--
-- 限制表 `qrtz_blob_triggers`
--
ALTER TABLE `qrtz_blob_triggers`
 ADD CONSTRAINT `qrtz_blob_triggers_ibfk_1` FOREIGN KEY (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`) REFERENCES `qrtz_triggers` (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`);
 
--
-- 限制表 `qrtz_cron_triggers`
--
ALTER TABLE `qrtz_cron_triggers`
 ADD CONSTRAINT `qrtz_cron_triggers_ibfk_1` FOREIGN KEY (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`) REFERENCES `qrtz_triggers` (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`);
 
--
-- 限制表 `qrtz_simple_triggers`
--
ALTER TABLE `qrtz_simple_triggers`
 ADD CONSTRAINT `qrtz_simple_triggers_ibfk_1` FOREIGN KEY (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`) REFERENCES `qrtz_triggers` (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`);
 
--
-- 限制表 `qrtz_simprop_triggers`
--
ALTER TABLE `qrtz_simprop_triggers`
 ADD CONSTRAINT `qrtz_simprop_triggers_ibfk_1` FOREIGN KEY (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`) REFERENCES `qrtz_triggers` (`SCHED_NAME`, `TRIGGER_NAME`, `TRIGGER_GROUP`);
 
--
-- 限制表 `qrtz_triggers`
--
ALTER TABLE `qrtz_triggers`
 ADD CONSTRAINT `qrtz_triggers_ibfk_1` FOREIGN KEY (`SCHED_NAME`, `JOB_NAME`, `JOB_GROUP`) REFERENCES `qrtz_job_details` (`SCHED_NAME`, `JOB_NAME`, `JOB_GROUP`);<br><br><br></em>

quartz集群實(shí)現(xiàn)原理,利用數(shù)據(jù)庫記錄job行為,并通過鎖機(jī)制,使job在同一次中僅運(yùn)行一次。

JobBean示例

//需要交由spring管理
@Service("dialogJob")
public class DialogJob {
 @Autowired
 private QuestionService questionService;
// 方法名在quartz定義
 public void execute() throws Exception{
  //具體執(zhí)行業(yè)務(wù) 
    questionService.XXXXX();
 } 
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI