You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java 8环境下Quartz任务无报错无日志挂起问题求助

问题描述

基于XML配置的Quartz任务在Java 7环境下运行正常,但升级至Java 8(具体版本jdk1.8.0_311)后,无论使用何种Cron表达式(当前测试为每5秒执行一次),任务在运行2-3次后就会挂起,无任何报错或日志输出。

曾怀疑问题源于数据库连接丢失(无报错)、连接池耗尽,或是Apache commons-vfs2库的问题,但单独创建了一个简单应用,通过JDBC执行数据库操作并连接SFTP,该应用运行正常。

环境与依赖
  • 项目类型:Maven管理的Web应用
  • 部署容器:Tomcat 8.5(尝试过Tomcat 9,问题依旧)
  • 核心依赖:Spring 4、Hibernate 3.6.9.Final、Apache commons-vfs2 2.7.0
  • 数据库:SQL Server
相关配置

数据库连接池配置

jdbc.driverClassName=net.sourceforge.jtds.jdbc.Drivercom.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:jtds:sqlserver://SERVER_ADDRESS:1433/SERVER_NAME
jdbc.username=USER
jdbc.password=PASS
jdbc.initialSize=5
jdbc.maxTotal=150
jdbc.maxIdle=15
jdbc.minIdle=5
jdbc.maxWaitMillis=10000
jdbc.validationQuery=SELECT 1

jdbc.validationQueryTimeout=10
jdbc.testOnBorrow=true
jdbc.testOnReturn=false
jdbc.testWhileIdle=false
jdbc.timeBetweenEvictionRunsMillis=1803000
jdbc.minEvictableIdleTimeMillis=1800000

jdbc.removeAbandonedOnMaintenance=true
jdbc.removeAbandonedOnBorrow=true
jdbc.removeAbandonedTimeout=300
jdbc.logAbandoned=true

Quartz任务XML Bean定义

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-2.5.xsd">
 
    
    <bean id="automaticInterviewImportJob"  class="cem.interview.importtool.quartz.InterviewImportJob" scope = "singleton">     
        
        
            
    </bean> 
    
    <bean id="automaticReportGenerationJob"     class="cem.interview.importtool.quartz.ReportGenerationJob" scope = "singleton">        
        
            
    </bean> 
    
    <!-- Address import job -->
    <bean id="automaticInterviewImportJobDetail" 
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="automaticInterviewImportJob" /> 
        <property name="targetMethod" value="run" />
        <property name="concurrent" value="false"/>
    </bean> 
    
    <bean id="automaticInterviewImportJobTriger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
<!--        class="org.springframework.scheduling.quartz.SimpleTriggerBean">       -->
            
            <property name="jobDetail" ref="automaticInterviewImportJobDetail"/>
             <property name="cronExpression" value="0/5 * * * * ? *"/>

    </bean> 
    
        <!-- Address import job -->
    <bean id="automaticGenerateExcelReportsJobDetail" 
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="automaticReportGenerationJob" /> 
        <property name="targetMethod" value="run" />
        <property name="concurrent" value="false"/>
    </bean> 
    
    <bean id="automaticGenerateExcelReportJobTriger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
<!--        class="org.springframework.scheduling.quartz.SimpleTriggerBean">       -->
            
            <property name="jobDetail" ref="automaticGenerateExcelReportsJobDetail"/>
             <property name="cronExpression" value="0/5 * * * * ? *"/>

    </bean> 

        
    <bean id="scheduler"    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    
        <property name="applicationContextSchedulerContextKey" value="applicationContext" />
        <property name="waitForJobsToCompleteOnShutdown" value="true" />
        <property name="jobFactory">
            <bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory"/>          
        </property>
    
        <property name="globalJobListeners">
            <list>

            </list>
        </property>
        <property name="triggers">
            <list>
                <ref bean="automaticInterviewImportJobTriger" />
                <ref bean="automaticGenerateExcelReportJobTriger" />
            </list>
        </property>
    </bean> 
</beans>

内容的提问来源于stack exchange,提问作者Naqash Subtain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 14:28:53