精华内容
下载资源
问答
  • Scheduler class: ‘org.quartz.core.QuartzScheduler’ - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool ‘org.quartz.simpl.SimpleThreadPool’ - ...

    最近在一次开发当中突然出现了这个问题,项目没有报错 一直在运行 也不知道是什么原因,明明上一次运行的时候没有报错。

    Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
      NOT STARTED.
      Currently in standby mode.
      Number of jobs executed: 0
      Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 20 threads.
      Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is clustered.
    
    

    最终通过navicat打开数据库的时候发现数据库连不上,数据库连接的另外一台公司的电脑的ip地址更换了,项目一直在运行的原因是因为一直在尝试连接数据库,当连接超时后再F8一下就会出现连接失败

    2020-03-04 13:37:13,015 [main] INFO  [org.quartz.core.QuartzScheduler] - Scheduler meta-data: Quartz Scheduler (v2.3.0) 'advert_quartzScheduler' with instanceId 'Alienware1583300165643'
      Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
      NOT STARTED.
      Currently in standby mode.
      Number of jobs executed: 0
      Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 20 threads.
      Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is clustered.
    
    2020-03-04 13:37:13,015 [main] INFO  [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'advert_quartzScheduler' initialized from an externally provided properties instance.
    2020-03-04 13:37:13,015 [main] INFO  [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler version: 2.3.0
    2020-03-04 13:37:13,017 [main] INFO  [org.quartz.core.QuartzScheduler] - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@6137cf6e
    2020-03-04 13:38:20,028 [main] WARN  [org.springframework.context.support.ClassPathXmlApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysJobService': Unsatisfied dependency expressed through field 'schedulerFactoryBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in file [E:\miguan_workspace\advert-parent\advert-biz-system\target\classes\config\spring-quartz.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
    Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysJobService': Unsatisfied dependency expressed through field 'schedulerFactoryBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in file [E:\miguan_workspace\advert-parent\advert-biz-system\target\classes\config\spring-quartz.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    	at com.advert.biz.system.main.SystemProvider.main(SystemProvider.java:20)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in file [E:\miguan_workspace\advert-parent\advert-biz-system\target\classes\config\spring-quartz.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    	... 15 more
    Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
    	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
    	at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:200)
    	at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:510)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    	... 25 more
    Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
    	at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2294)
    	at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2039)
    	at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533)
    	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:246)
    	... 30 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    	at com.mysql.jdbc.Util.getInstance(Util.java:387)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    	at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163)
    	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088)
    	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
    	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
    	at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:39)
    	at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256)
    	at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2304)
    	at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2290)
    	... 33 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
    	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
    	at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104)
    	... 47 more
    Caused by: java.net.ConnectException: Connection timed out: connect
    	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    	at java.net.Socket.connect(Socket.java:589)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
    	... 49 more
    ``
    更换数据库连接ip地址即可
    
    展开全文
  • nested exception is org.quartz.SchedulerException: The Scheduler cannot be restarted after shutdown() has been called. at org.springframework.scheduling.quartz.SchedulerFactoryBean$1.run...
  • org.quartz.tool包源码

    2016-12-29 12:35:12
    org.quartz.tool包源码,使用方法请搜索《 quartz-2.2.1定制工具类,方便nutz使用js配置quartz》
  • 前言 springboot内置有org.springframework.scheduling.annotation.Scheduled可以让我们进行简单快速的任务调度(例如定时...在这种情况,博主使用了quartz,写下此文以记; 依赖(gradle) compile group: 'org.q

    前言

    springboot内置有org.springframework.scheduling.annotation.Scheduled可以让我们进行简单快速的任务调度(例如定时执行的任务),当我们一些和任务调度有关的业务开始复杂的时候,极其需要非常灵活的任务调度策略;在这种情况,博主使用了quartz,写下此文以记;
    

    依赖(gradle)

        compile group: 'org.quartz-scheduler', name: 'quartz', version: '2.2.1'
    

    quartz的配置文件

    springboot中集成quartz并进行持久化配置,在springboot项目中的resources目录下创建properties文件(和springboot的配置文件同级),命名quartz.properties;
    

    内容如下:

    # 固定前缀org.quartz
    # 主要分为scheduler、threadPool、jobStore、plugin等部分
    #
    #实例名
    org.quartz.scheduler.instanceName=TioadScheduler
    #实例id(唯一,有缺省值)
    org.quartz.scheduler.instanceId=TioadSchedulerId
    org.quartz.scheduler.rmi.export=false
    org.quartz.scheduler.rmi.proxy=false
    org.quartz.scheduler.wrapJobExecutionInUserTransaction=false
    # 实例化ThreadPool时,使用的线程类为SimpleThreadPool
    org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
    # threadCount和threadPriority将以setter的形式注入ThreadPool实例
    # 并发个数
    org.quartz.threadPool.threadCount=5
    # 优先级
    org.quartz.threadPool.threadPriority=5
    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
    org.quartz.jobStore.misfireThreshold=5000
    # 默认存储在内存中
    #org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
    #持久化
    org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
    org.quartz.jobStore.tablePrefix=QRTZ_
    org.quartz.jobStore.dataSource=qzDS
    org.quartz.dataSource.qzDS.driver=com.mysql.jdbc.Driver
    #dev(第一次初始化quartz,需要执行quartz包下的sql,创建表结构)
    org.quartz.dataSource.qzDS.URL=持久化的数据库url配置
    org.quartz.dataSource.qzDS.user=持久化的数据库连接用户账号配置
    org.quartz.dataSource.qzDS.password=持久化的数据库连接用户密码配置
    org.quartz.dataSource.qzDS.maxConnections=10

    持久化数据库建表

    官网下载对应版本的quartz,解压,目录下的docs/dbTables会有大多数数据库的建表语句,执行建表;

    基于注解的quartz配置

    import org.quartz.Scheduler;
    import org.quartz.ee.servlet.QuartzInitializerListener;
    import org.springframework.beans.factory.config.PropertiesFactoryBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.scheduling.quartz.SchedulerFactoryBean;
    
    import java.io.IOException;
    import java.util.Properties;
    
    @Configuration
    public class SchedulerConfig {
    @Autowired
    TioadJobFactory tioadJobFactory;//注入我们自己的factory,防止无法在job中注入service层
    
        @Bean(name="TioadSchedulerFactory")
        public SchedulerFactoryBean tioadSchedulerFactoryBean() throws IOException {
            SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
            schedulerFactoryBean.setQuartzProperties(quartzProperties());
    //        schedulerFactoryBean.setJobFactory(tioadJobFactory);
            return schedulerFactoryBean;
        }
    
        @Bean
        public Properties quartzProperties() throws IOException {
            PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
            propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
            //在quartz.properties中的属性被读取并注入后再初始化对象
            propertiesFactoryBean.afterPropertiesSet();
            return propertiesFactoryBean.getObject();
        }
    
        /*
         * quartz初始化监听器
         */
        @Bean
        public QuartzInitializerListener executorListener() {
            return new QuartzInitializerListener();
        }
    
        /*
         * 通过SchedulerFactoryBean获取Scheduler的实例
         */
        @Bean(name="TioadScheduler")
        public Scheduler scheduler() throws IOException {
            return tioadSchedulerFactoryBean().getScheduler();
        }

    新建测试任务Job1

    实现quartz的job接口,重写execute(),这里就是任务的逻辑,在execute()中执行的任务逻辑如果用到service层,发现注入不成功的话,需要在上面的SchedulerConfig.class中set我们自己的;
    
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    import org.springframework.stereotype.Component;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    @Component
    public class Job1 implements Job {
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
            System.out.println("job 1 " + sdf.format(new Date()));
        }
    }

    我们自己的工厂防止无法注入问题TioadJobFactory

    @Component
    public class TioadJobFactory extends AdaptableJobFactory {
    
        @Autowired
        private AutowireCapableBeanFactory capableBeanFactory;
    
        @Override
        protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
            Object jobInstance = super.createJobInstance(bundle);
            capableBeanFactory.autowireBean(jobInstance); //这一步解决不能spring注入bean的问题
            return jobInstance;
        }
    
    }

    controller级测试使用quartz

    import com.crm.restapi.param.QuartzParam;
    import com.crm.restapi.result.ApiResult;
    import org.quartz.*;
    import org.quartz.impl.matchers.GroupMatcher;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.*;
    
    import javax.validation.Valid;
    import java.util.HashMap;
    import java.util.Set;
    
    import static org.quartz.CronScheduleBuilder.cronSchedule;
    import static org.quartz.JobBuilder.newJob;
    import static org.quartz.TriggerBuilder.newTrigger;
    
    @Validated
    @RequestMapping(value = "/task")
    @RestController
    public class TaskController extends BaseController{
        @Autowired @Qualifier("TioadScheduler")//这里是config里面定义的scheduler,通过添加注解@Qualifier,使@Autowired的自动注入由bytype变为byname
        private Scheduler scheduler;
        @Value("${quartzname}")
        private String quartzname;//这是我自己定义的quartzname,这里是字符串:IamROOT
        @Value("${quartzpath}")
        private String quartzpath;//这是配置好的反射path,这里是:com.crm.restapi.schedule.job.
    
        @PostMapping(value = "/startjob")
        public ApiResult startjob(@RequestBody @Valid QuartzParam quartzParam) throws ClassNotFoundException, SchedulerException {
            // 定义jobdetail
            Class jobclass = Class.forName(quartzpath + quartzParam.getClassName());
            JobDetail job = newJob(jobclass)
                    .withIdentity(quartzParam.getJobName(), quartzParam.getJobGroup())
                    .build();
            // 定义trigger触发器
            Trigger trigger = newTrigger()
                    .withIdentity(quartzParam.getTgName(), quartzParam.getTgGroup())
                    .startNow()
                    .withSchedule(cronSchedule(quartzParam.getTrigger()))//这里是cron表达式
                    .build();
            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job, trigger);//定义的JobDetail和trigger注册到scheduler里
            return new ApiResult().success();
        }
    
        @GetMapping("/start")
        public ApiResult startTask() throws ClassNotFoundException, SchedulerException {
            scheduler.start();
            return new ApiResult().success();
        }
    
        @GetMapping("/stop")
        public ApiResult stopTrigger() throws ClassNotFoundException, SchedulerException {
            scheduler.standby();//这里使用standby()方法,shutdown()方法会把scheduler实例关闭,start也会无法启动
            return new ApiResult().success();
        }
    
        @GetMapping("/list")
        public ApiResult list() throws ClassNotFoundException, SchedulerException {
            HashMap map = new HashMap();
            Set<JobKey> jobKeySet = scheduler.getJobKeys(GroupMatcher.groupEquals("group1"));
            map.put("jobNum", jobKeySet.size());
            map.put("jobDedail", jobKeySet);
            map.put("nowJob", scheduler.getCurrentlyExecutingJobs());
            return new ApiResult().success(map);
        }
    
    }
    

    QuartzParam.java(这里我用了validation验证)

    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    
    public class QuartzParam {
        @Size(min = 1, message = "类(名)不能为空")
        @NotNull(message = "类(名)不能为空")
        private String className;
        @Size(min = 1, message = "任务(名)不能为空")
        @NotNull(message = "任务(名)不能为空")
        private String jobName;
        @Size(min = 1, message = "任务(名)不能为空")
        @NotNull(message = "任务(名)不能为空")
        private String jobGroup;
        @Size(min = 1, message = "触发器(名)不能为空")
        @NotNull(message = "触发器(名)不能为空")
        private String tgName;
        @Size(min = 1, message = "触发器(组)不能为空")
        @NotNull(message = "触发器(组)不能为空")
        private String tgGroup;
        @Size(min = 1, message = "触发器(规则)不能为空")
        @NotNull(message = "触发器(规则)不能为空")
        private String trigger;
    
        public String getClassName() {
            return className;
        }
    
        public void setClassName(String className) {
            this.className = className;
        }
    
        public String getJobName() {
            return jobName;
        }
    
        public void setJobName(String jobName) {
            this.jobName = jobName;
        }
    
        public String getJobGroup() {
            return jobGroup;
        }
    
        public void setJobGroup(String jobGroup) {
            this.jobGroup = jobGroup;
        }
    
        public String getTgName() {
            return tgName;
        }
    
        public void setTgName(String tgName) {
            this.tgName = tgName;
        }
    
        public String getTgGroup() {
            return tgGroup;
        }
    
        public void setTgGroup(String tgGroup) {
            this.tgGroup = tgGroup;
        }
    
        public String getTrigger() {
            return trigger;
        }
    
        public void setTrigger(String trigger) {
            this.trigger = trigger;
        }
    }
    

    Run起来

    springboot启动后scheduler实例会自动start
    

    这里写图片描述

    使用postman测试
    stop
    

    这里写图片描述
    console
    这里写图片描述
    start
    这里写图片描述
    console
    这里写图片描述
    list
    这里写图片描述
    startjob
    这里写图片描述
    console
    这里写图片描述

    检查持久化

    前面步骤,早就已经创建好的数据库表
    

    这里写图片描述

        查看
    

    这里写图片描述
    这里写图片描述

        持久化成功(第一条别纠结,那是我以前用的,第二条数据才是我们测的)
    

    简单快速上手springboot集成quartz的快速教程,简单粗暴的还是需要官方文档;
    有问题,欢迎留言;
    

    demo源码

    附上官方文档
    org.quartz-scheduler官方文档

    quartz学习
    Quartz学习——Quartz大致介绍(一)

    常见问题
    quartz Couldn’t rollback jdbc connection. Communications link failure during rollback().

    java.net.SocketException: Broken pipe with Quartz and MySQL and Tomcat (Tomcat Crash)

    展开全文
  • 自己的SSM项目中要用到定时器,初期...后来就研究quartz,准备整合到项目中。遇到了异常,异常内容如下: [2019-03-25 10:23:57,904] [org.springframework.web.servlet.DispatcherServlet] : Context initiali...

     

      自己的SSM项目中要用到定时器,初期使用Timer,后来用spring 的schedule,都比较简单,所以功能比较单一。后来就研究quartz,准备整合到项目中。遇到了异常,异常内容如下:

    [2019-03-25 10:23:57,904] [org.springframework.web.servlet.DispatcherServlet] : Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduleReportFactory' defined in class path resource [springmvc-servlet.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Couldn't clean volatile data: Unknown column 'IS_VOLATILE' in 'where clause' [See nested exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'IS_VOLATILE' in 'where clause']]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2527)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2516)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Couldn't clean volatile data: Unknown column 'IS_VOLATILE' in 'where clause' [See nested exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'IS_VOLATILE' in 'where clause']]
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.initialize(JobStoreSupport.java:582)
        at org.quartz.impl.jdbcjobstore.JobStoreCMT.initialize(JobStoreCMT.java:144)
        at org.springframework.scheduling.quartz.LocalDataSourceJobStore.initialize(LocalDataSourceJobStore.java:161)
        at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1220)
        at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1371)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:595)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:478)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
        ... 35 more
    Caused by: org.quartz.JobPersistenceException: Couldn't clean volatile data: Unknown column 'IS_VOLATILE' in 'where clause' [See nested exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'IS_VOLATILE' in 'where clause']
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanVolatileTriggerAndJobs(JobStoreSupport.java:765)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport$1.execute(JobStoreSupport.java:726)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport$40.execute(JobStoreSupport.java:3677)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3711)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3673)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanVolatileTriggerAndJobs(JobStoreSupport.java:722)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.initialize(JobStoreSupport.java:580)
        ... 43 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'IS_VOLATILE' in 'where clause'
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
        at com.mysql.jdbc.Util.getInstance(Util.java:383)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
        at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2714)
        at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeQuery(FilterEventAdapter.java:465)
        at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2711)
        at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeQuery(PreparedStatementProxyImpl.java:145)
        at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227)
        at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectVolatileTriggers(StdJDBCDelegate.java:3493)
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanVolatileTriggerAndJobs(JobStoreSupport.java:743)
        ... 49 more

      

      遇到这个异常,我是这样做的:

    1)起初我怀疑我导入的数据库脚本不对,我就把数据库删了,然后我重新执行了脚本,结果还是报这个异常;

    2)之后我上网查,有网友说spring版本与quartz版本不兼容,试了无效;

    3)有网友说,maven中配置的quartz版本与数据库脚本中的版本不匹配,因为quartz各个版本之间的差异还是挺大的,所以我就从quartz官网下了压缩包,然后从maven仓库下了依赖,依然无效;

     

      整合失败,万般无奈,我甚至要怀疑人生了,明明是按照网上的教程一步步整合的啊,貌似也没毛病啊。我记得最后有一次,我在maven中修改quartz的版本,因为项目中依赖太多了,所以我就全局搜索,结果搜索到两处quartz,原来项目中有集成shiro,shiro里已经包括了quartz,出异常的原因就是“shiro与quartz冲突”,所以解决冲突就完了,附上解决办法:问题篇-解决shiro和quartz 版本冲突问题。至此异常得以解决。

     

    转载于:https://www.cnblogs.com/DDgougou/p/10593596.html

    展开全文
  • org.quartz.jobStore.driverDelegateClass

    千次阅读 2020-01-10 09:20:05
    org.quartz.jobStore.driverDelegateClass quartz.properties 中的属性解释: Driver代表了解不同数据库系统的特定“方言”。可能的选择包括: org.quartz.impl.jdbcjobstore.StdJDBCDelegate(用于完全符合JDBC的...

    org.quartz.jobStore.driverDelegateClass quartz.properties 中的属性解释:

    Driver代表了解不同数据库系统的特定“方言”。可能的选择包括:

    org.quartz.impl.jdbcjobstore.StdJDBCDelegate(用于完全符合JDBC的驱动程序)
    org.quartz.impl.jdbcjobstore.MSSQLDelegate(对于Microsoft SQL Server和Sybase)
    org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
    org.quartz.impl.jdbcjobstore.WebLogicDelegate(对于WebLogic驱动程序)
    org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
    org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate(对于Weblogic中使用的Oracle驱动程序)
    org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate(对于在Weblogic中使用的Oracle驱动程序)
    org.quartz.impl.jdbcjobstore.CloudscapeDelegate
    org.quartz.impl.jdbcjobstore.DB2v6Delegate
    org.quartz.impl.jdbcjobstore.DB2v7Delegate
    org.quartz.impl.jdbcjobstore.DB2v8Delegate
    org.quartz.impl.jdbcjobstore.HSQLDBDelegate
    org.quartz.impl.jdbcjobstore.PointbaseDelegate
    org.quartz.impl.jdbcjobstore.SybaseDelegate
    
    展开全文
  • 使用Quartz 2,在运行项目时... org.quartz.SchedulerConfigException: Thread count must be > 0 at org.quartz.simpl.SimpleThreadPool.initialize(SimpleThreadPool.java:245) at org.quartz.impl.StdSched...
  • org.quartz.jobStore.misfireThreshold = 60000 这个参数一般在多线程池条件下无效。 产生misfire失败的条件: 单线程执行定时任务 第一个任务的执行完后的结束时间 减去 第二个任务的开始时间 = 时...
  • 在整合Quartz的时候,新建了5个调度任务,...2019-11-12 02:36:25.796 [schedulerFactoryBean_QuartzSchedulerThread] ERROR org.quartz.core.ErrorLogger - An error occured instantiating job to be executed. ...
  • quartz任务执行报错 ...Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:284) at init.Q...
  • org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'myDS': org.apache....
  • quartz异常之:org.quartz.SchedulerException

    万次阅读 2019-04-30 11:14:35
    一、问题 ...org.quartz.SchedulerException:Couldn'tgethostname! atorg.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:36) atorg.quartz.impl.StdSch...
  • 问题描述: 2020-11-19 15:22:06.141 [restartedMain] INFO ...2020-11-19 15:22:06.952 INFO 1352 --- [lerFactoryBean]] o.s.s.quartz.SchedulerFactoryBean : Starting Quartz Scheduler now, after
  • org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysJobController': Unsatisfied dependency expressed through field 'jobService'; nested exce...
  • Spring的监听器和org.quartz.Job的使用

    千次阅读 2017-10-26 15:41:44
    "org.springframework.scheduling.quartz.SchedulerFactoryBean" > < property name = "jobFactory" ref = "jobFactory" > property > bean > 3.spring-mvc.xml < context :annotation-config />...
  • 1、quartz版本:2.2.0 2、spring版本:4.2.6.RELEASE 二、定义接口 public interface ServiceI { void getMsg(); }三、定义任务实现类 @Service("serviceImpl") public class ServiceImpl implements ServiceI { ...
  • 最近遇到一个问题,部署在...2019-05-17 11:33:03.796 [localhost-startStop-1] [INFO ] com.netinfosz.frame.quartz.bean.SchedulerFactoryBeanWithShutdownDelay Loading Quartz config from [ServletContext...
  • Caused by: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table 'amops.QRTZ_LOCKS' doesn't exist 因为在Linux平台下面MySQL默认是严格区分大小写的,需要去修改MySQL的配置文件 ...
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#1' defined in file [D:\mavenproject\service-isv-duck\...
  • quartz集成到SSM框架中遇到的...java.lang.NoSuchMethodError:org.springframework.scheduling.quartz.SchedulerFactoryBean.getScheduler()Lorg/quartz/Scheduler; java.lang.NoSuchMethodError: org.quartz.Sch...
  • org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'doTime' defined in class path resource
  • 底层系统 用的是org.quartz-scheduler-quartz1.6.2 我在maven仓库中没有找到,后来发现maven仓库中有2.3.0,就把版本号修改了,库中还有一个1.8.6但是看到不是新版本就没有使用。 就这样移植完成之后就进行启动项目...
  • Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: invalid stream header: C2ACED9C at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1538) ...
  • 原因:我本地是Window平台,此平台下面Mysql默认是不区分下小写的,而服务器时Linux平台,在linux平台下面Mysql默认是严格区分大小写的。此时,修改Mysql配置文件让其不区分大小写,问题解决。。...
  • 2019/06/03 10:26:05 [ERROR] ERROR org.quartz.core.JobRunShell -> Job DEFAULT.TASK_b469fd77fc514ef8b15899a72f941b18 threw an unhandled Exception: java.lang.ClassCastException: io.unify.modules.jo...
  • Quartz报错误:org.quartz.SchedulerException: Based on configured schedule, the given trigger will never fire. 原因:设置的某个任务触发器时间比当前时间小永远不会触发或者cron表达式不合法 解决办法:...
  • Quartz定时器错误信息,java.lang.NoSuchMethodError: org.quartz.SchedulerException 2013-01-04 17:10 4551人阅读 评论(0) 收藏 举报  分类:   Java(23)  版权声明:本文为博主...
  • org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table 'aly_uias.qrtz_LOCKS' doesn't exist 异常信息表明:在创建quartz自带表时,表明是小写的,程序中使用的是大写表明,由于...
  • org.quartz.JobPersistenceException

    千次阅读 2018-06-01 14:37:56
    Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: Table 'framework.QRTZ_TRIGGERS' doesn't exist [See nested exception: ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 42,683
精华内容 17,073
关键字:

org.quartz