Quartz调度程序无法从数据源获取数据库连接

时间:2017-10-30 14:24:03

标签: java mysql quartz

我正在尝试使用mysql数据库设置quartz调度程序,并且我得到了以下异常。请有人帮我这个,拜托。

我已经包含了以下的罐子:

c3p0-0.9.1.1.jar
JTA-1.1.jar
MySQL的连接器的Java-5.1.27.jar
石英2.2.1.jar
石英工作-2.2.1.jar
SLF4J-API 1.7.10.jar
slf4j-simple-1.7.25.jar

[LMWJobScheduler_QuartzSchedulerThread] ERROR org.quartz.core.ErrorLogger - An error occurred while scanning for the next triggers to fire.
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'myDS': java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [lastAcquisitionFailureDefaultUser] ] has been closed() -- you can no longer use it. [See nested exception: java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [lastAcquisitionFailureDefaultUser] ] has been closed() -- you can no longer use it.]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:778)
at org.quartz.impl.jdbcjobstore.JobStoreTX.getNonManagedTXConnection(JobStoreTX.java:71)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3784)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTriggers(JobStoreSupport.java:2756)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:272)
Caused by: java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [lastAcquisitionFailureDefaultUser] ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.assertCpds(AbstractPoolBackedDataSource.java:447)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getPoolManager(AbstractPoolBackedDataSource.java:459)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.quartz.utils.PoolingConnectionProvider.getConnection(PoolingConnectionProvider.java:247)
at org.quartz.utils.DBConnectionManager.getConnection(DBConnectionManager.java:108)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:775)
... 4 more

这是quartz.properties

org.quartz.scheduler.instanceName: JobScheduler
org.quartz.scheduler.instanceId: AUTO
org.quartz.scheduler.skipUpdateCheck: true

org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 20
org.quartz.threadPool.threadPriority: 5

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true

org.quartz.dataSource.myDS.driver: com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL: jdbc:mysql://localhost:3306/quartz
org.quartz.dataSource.myDS.user: root
org.quartz.dataSource.myDS.password: password
org.quartz.dataSource.myDS.maxConnections: 5

石英-config.xml中

http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd"                      版本=" 2.0">

<schedule>
    <job>
        <name>Hello</name>
        <group>HelloGroup</group>

        <description>The job description</description>
        <job-class>HelloJob</job-class>
    </job>       
    <trigger>
        <cron>
            <name>hello-trigger</name>
            <group>Hello_Group</group>
            <job-name>Hello</job-name>

            <job-group>HelloGroup</job-group>
            <cron-expression>0/30 0/1 * 1/1 * ?</cron-expression>

        </cron>
    </trigger>        
</schedule>

主要课程

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

  public class QuartzTest {
    public static void main(String[] args) {

    try {
        // Grab the Scheduler instance from the Factory
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        // and start it off
        scheduler.start();

        scheduler.shutdown();

    } catch (SchedulerException se) {
        se.printStackTrace();
        }
    }
}

工作班

import org.quartz.Job;
import org.quartz.JobExecutionContext;

public class HelloJob implements Job {
    public void execute(JobExecutionContext context){
        System.out.println("Hello World !!!");
    }
}

1 个答案:

答案 0 :(得分:1)

我找到了问题的原因。

scheduler.shutdown();

此语句在作业触发器之前关闭石英服务器,并且连接不再可用。