加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Quartz Scheduler不使用JDBCStore在DB中插入记录

发布时间:2020-12-15 02:18:03 所属栏目:Java 来源:网络整理
导读:配置Quartz作业, public static void schedule(IEntity entity,Date startdate) { try { JobDetail job = JobBuilder.newJob(StatingUpdateJob.class) .withIdentity("UpdateStagingRecords" + entity.getId(),"StgToProduction").build(); JobDataMap data
配置Quartz作业,

public static void schedule(IEntity entity,Date startdate) {
    try {
        JobDetail job = JobBuilder.newJob(StatingUpdateJob.class)
                .withIdentity("UpdateStagingRecords" + entity.getId(),"StgToProduction").build();
        JobDataMap data = new JobDataMap(new HashMap<>());
        data.put("Entity",entity);
        job.getJobBuilder().setJobData(data);

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        Date enddate = new Date();
        enddate.setTime(startdate.getTime() + 6000000);
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withIdentity("UpdateStagingRecords" + entity.getId(),"StgToProduction").startAt(startdate)
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/5 * 1/1 * ? *")
                        .withMisfireHandlingInstructionDoNothing())
                .endAt(enddate).build();
        Connection connection = DBConnectionManager.getInstance().getConnection("myDS");
        System.out.println(connection);
        scheduler.scheduleJob(job,cronTrigger);
        scheduler.start();
    } catch (Exception e) {
        System.out.println("Something went wrong");
        e.printStackTrace();
    }

}

然后将quartz.properties放在我的类路径中

org.quartz.scheduler.instanceName=JavacodeGeeksScheduler
org.quartz.scheduler.instanceId=99199
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=3
org.quartz.context.key.QuartzTopic=QuartzPorperties
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.dataSource=myDS
org.quartz.jobListener.NAME.class=com.javacodegeeks.quartz.MyJobListener
org.quartz.dataSource.myDS.driver=com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL=jdbc:mysql://localhost/test
org.quartz.dataSource.myDS.user=admin
org.quartz.dataSource.myDS.password=admin
org.quartz.dataSource.myDS.maxConnections=30

我的工作成功创建并正确触发.但是,工作细节并没有放在数据库中.这是我的桌子

enter image description here

不确定我还需要配置什么.

解决方法

奇怪的是,石英数据源URL不接受与本机jdbc url相同的内容.

当我将jdbc:mysql:// localhost / test更改为

jdbc:mysql://localhost:3306/test

它工作了(感谢@pringi和@Bilbo Baggins).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读