Quartz Scheduler延迟启动

时间:2019-03-01 16:55:36

标签: mysql wildfly quartz

我正在使用Quartz 2.2.1,Wildfly 14和Mysql8。我遇到的问题是,石英调度程序在启动wildfly之后晚启动(即大约50-60分钟后)。

启用Wildfly之后,我会在当前时间的3-4分钟后使用网络应用程序来安排作业(DailyHouseKeepingEvent)。但是作业在选定的时间没有执行。但是在约50/60分钟后,我可以在日志中看到启动了石英调度程序,然后执行了我的工作。发生这种情况后,我可以通过在特定时间进行设置来成功执行作业。事后一切正常。

从我的日志文件中提取:

14:49:39,790 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 14.0.0.Final (WildFly Core 6.0.1.Final) started in 108016ms - Started 1415 of 1601 services (361 services are lazy, passive or on-demand)
14:54:49,308 INFO  [org.springframework.scheduling.quartz.LocalDataSourceJobStore] (QuartzScheduler_schedulerFactory-MC0A8J0C1551451723948_MisfireHandler) Handling 2 trigger(s) that missed their scheduled fire-time.
14:56:49,313 INFO  [org.springframework.scheduling.quartz.LocalDataSourceJobStore] (QuartzScheduler_schedulerFactory-MC0A8J0C1551451723948_MisfireHandler) Handling 2 trigger(s) that missed their scheduled fire-time.
... **Lot of messages that informs that 2 trigger(s) missed their scheduled fire-time**
........
**after ~50/60 mins**
............
2019-03-01 16:07:56,664 DEBUG [org.quartz.xml.XMLSchedulingDataProcessor] (Quartz Scheduler [schedulerFactory]) Found 31 job definitions.
2019-03-01 16:07:56,680 DEBUG [org.quartz.xml.XMLSchedulingDataProcessor] (Quartz Scheduler [schedulerFactory]) Parsed job definition: JobDetail 'DEFAULT.CheckInOpenEvent':  jobClass: 'com.eurostar.app.edcs.service.scheduler.event.CheckInOpenEvent concurrentExectionDisallowed: false persistJobDataAfterExecution: false isDurable: true requestsRecovers: false
**....<31 job names displayed..>**
2019-03-01 16:07:57,294 ERROR [org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin] (Quartz Scheduler [schedulerFactory]) Error scheduling jobs: Encountered 227 validation exceptions.: org.quartz.xml.ValidationException: Encountered 227 validation exceptions.
    at org.quartz.xml.XMLSchedulingDataProcessor.maybeThrowValidationException(XMLSchedulingDataProcessor.java:1242)
    at org.quartz.xml.XMLSchedulingDataProcessor.processFile(XMLSchedulingDataProcessor.java:478)
    at org.quartz.xml.XMLSchedulingDataProcessor.processFileAndScheduleJobs(XMLSchedulingDataProcessor.java:860)
....
Caused by: org.xml.sax.SAXParseException; systemId: file:///C:/Users/A581781/git/EDCS/EDCS_SCH/EDCSSCHED/resources/quartz_jobs.xml; lineNumber: 7; columnNumber: 15; schema_reference.4: Failed to read schema document 'http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:201)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:132)
....

2019-03-01 16:07:57,296 ERROR [org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin] (Quartz Scheduler [schedulerFactory]) Failed to resolve UserTransaction for plugin: jobInitializer: javax.transaction.RollbackException: ARJUNA016102: The transaction is not active! Uid is 0:ffffac1fe011:5f6bbd0f:5c794633:11
    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1278)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
    at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
    at org.wildfly.transaction.client.LocalTransaction.commitAndDissociate(LocalTransaction.java:77)
    at org.wildfly.transaction.client.ContextTransactionManager.commit(ContextTransactionManager.java:71)
    at org.wildfly.transaction.client.LocalUserTransaction.commit(LocalUserTransaction.java:53)
    at org.quartz.ee.jta.UserTransactionHelper$UserTransactionWithContext.commit(UserTransactionHelper.java:202)
    at org.quartz.plugins.SchedulerPluginWithUserTransactionSupport.resolveUserTransaction(SchedulerPluginWithUserTransactionSupport.java:196)
    at org.quartz.plugins.SchedulerPluginWithUserTransactionSupport.start(SchedulerPluginWithUserTransactionSupport.java:146)
    at org.quartz.core.QuartzScheduler.startPlugins(QuartzScheduler.java:2407)
    at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:568)
    at org.quartz.impl.StdScheduler.start(StdScheduler.java:142)
    at org.springframework.scheduling.quartz.SchedulerFactoryBean$1.run(SchedulerFactoryBean.java:669)

2019-03-01 16:07:57,296 INFO  [org.quartz.core.QuartzScheduler] (Quartz Scheduler [schedulerFactory]) Scheduler schedulerFactory_$_MC0A8J0C1551451723948 started.
**.... // Then job starts execution as normal**

quartz-jobs.xml

<?xml version="1.0" encoding="utf-8"?>
<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData 
    http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">

    <schedule>
        <job>
            <name>CheckInOpenEvent</name>
            <group>DEFAULT</group>
            <description>
                A job CheckInOpenEvent
            </description>
            <job-class>com.eurostar.app.edcs.service.scheduler.event.CheckInOpenEvent</job-class>
            <durability>true</durability>
        </job>
    </schedule>
.......
// other jobs
...
<schedule>
        <job>
            <name>EDCSLogEvent</name>
            <group>DEFAULT</group>
            <description>
                This event is used to generate log files.
            </description>
            <job-class>com.eurostar.app.edcs.service.scheduler.event.EDCSLogEvent</job-class>
            <durability>false</durability>
        </job>

        <trigger>
            <cron>
                <name>EDCSLogEventTrigger</name>
                <group>DEFAULT</group>
                <job-name>EDCSLogEvent</job-name>
                <job-group>DEFAULT</job-group>
                <cron-expression>0 0/2 * * * ?</cron-expression>
            </cron>
        </trigger>
    </schedule>
</job-scheduling-data>

quartz.properties

org.quartz.scheduler.instanceName = EDCSScheduler
org.quartz.scheduler.instanceId = AUTO

org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000

org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
org.quartz.scheduler.userTransactionURL=java:jboss/UserTransaction

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 20
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

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

org.quartz.jobStore.tablePrefix = qrtz_
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.useProperties = true


org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = myDS

org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true


org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = C:\Users\A581781\git\EDCS\EDCS_SCH\EDCSSCHED\resources\quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.wrapInUserTransaction = true

edcs-scheduler-quartzContext.xml

<?resources.xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="edcsDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiEnvironment" >
            <props>
                <prop key="java.naming.factory.initial">org.jboss.as.naming.InitialContextFactory</prop>
            </props>
        </property>
        <property name="jndiName" value="edcs/edcsDataSourceReadOnly"/>
    </bean>
    <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="dataSource" ref="edcsDS"/>
        <property name="autoStartup"><value>true</value></property>
        <property name="applicationContextSchedulerContextKey">
            <value>applicationContext</value>
        </property> 
        <property name="startupDelay"><value>20</value></property>
        <property name="waitForJobsToCompleteOnShutdown"><value>true</value></property> 
        <property name="quartzProperties">
            <props>
                <prop key="org.quartz.scheduler.instanceName">EDCSScheduler</prop>
                <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                <prop key="org.quartz.scheduler.userTransactionURL">java:jboss/UserTransaction</prop>
                <!-- ThreadPool -->
                <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                <prop key="org.quartz.threadPool.threadCount">20</prop>
                <prop key="org.quartz.threadPool.threadPriority">5</prop>
                <!-- Job store -->
                <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
                <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreCMT</prop>
                <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
                <prop key="org.quartz.jobStore.useProperties">false</prop>
                <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}locks UPDLOCK WHERE LOCK_NAME = ?</prop>
                <prop key="org.quartz.jobStore.isClustered">true</prop>
                <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
                <prop key="org.quartz.jobStore.nonManagedTXDataSource">edcsDataSourceReadOnly</prop>
                <prop key="org.quartz.dataSource.edcsDataSourceReadOnly.jndiURL">edcs/edcsDataSourceReadOnly</prop>
                <prop key="org.quartz.plugin.jobInitializer.class">org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin</prop>
                <prop key="org.quartz.plugin.jobInitializer.fileNames">C:\Users\A581781\git\EDCS\EDCS_SCH\EDCSSCHED\resources\quartz_jobs.xml</prop>
                <prop key="org.quartz.plugin.jobInitializer.wrapInUserTransaction">true</prop>
                <prop key="org.quartz.plugin.jobInitializer.failOnFileNotFound">true</prop>
                <!-- Plugins -->
                <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop>
            </props>
        </property>
        </bean>

    <!-- JDBC Template -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="edcsDS"/>
    </bean> 
</beans>

0 个答案:

没有答案