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>