Spring 调度处理,异常被吃掉问题

public class CreateBillingEventJob extends QuartzJobBean implements StatefulJob {

@Override
    
protected void executeInternal(JobExecutionContext context){

.... //这里如果出现异常

}



}

父类QuartzJobBean ,不会处理异常,会将异常给调用者处理

public abstract class QuartzJobBean implements Job {



/*

* This implementation applies the passed-in job data map as bean property

* values, and delegates to <code>executeInternal</code> afterwards.

* @see #executeInternal

*/

public final void execute(JobExecutionContext context) throws JobExecutionException {

try {

    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);

    MutablePropertyValues pvs = new MutablePropertyValues();

    pvs.addPropertyValues(context.getScheduler().getContext());

    pvs.addPropertyValues(context.getMergedJobDataMap());

    bw.setPropertyValues(pvs, true);

}

catch (SchedulerException ex) {

    throw new JobExecutionException(ex);

}

executeInternal(context);

}



protected abstract void executeInternal(JobExecutionContext context) throws     JobExecutionException;



}

调用者处理时捕获了异常并吃掉了异常,只有当打印当前类时才会输出异常信息

public class JobRunShell implements Runnable {



.....

try {

    log.debug("Calling execute on job " + jobDetail.getFullName());

    job.execute(jec);

    endTime = System.currentTimeMillis();

} catch (JobExecutionException jee) {

    endTime = System.currentTimeMillis();

    jobExEx = jee;

    getLog().info("Job " + jobDetail.getFullName() +

    " threw a JobExecutionException: ", jobExEx);

} catch (Exception e) {

    endTime = System.currentTimeMillis();

    getLog().error("Job " + jobDetail.getFullName() +

    " threw an unhandled Exception: ", e);

    SchedulerException se = new SchedulerException(

    "Job threw an unhandled exception.", e);

    se.setErrorCode(SchedulerException.ERR_JOB_EXECUTION_THREW_EXCEPTION);

    qs.notifySchedulerListenersError("Job ("+ jec.getJobDetail().getFullName()+ " threw an exception.", se);

    jobExEx = new JobExecutionException(se, false);

    jobExEx.setErrorCode(JobExecutionException.ERR_JOB_EXECUTION_THREW_EXCEPTION);

}

因此在异常类中需要注意异常处理 ,不然后台日志中将会不显示错误信息 ,建议处理方式如下

方法1: 为了更好的发现问题 CreateBillingEventJob 类最好捕获异常并打印

方法2: 需改log4j的文件,打印出表达式对应的异常包里的问题,这种处理方式需要考虑是打印日志等级和日志量

<category name="org.quartz.core">

<priority value="ERROR"/>

</category>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

=PNZ=BeijingL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值