您的位置:首页 > 其它

Quartz:ERROR threw an unhandled Exception

2016-06-28 17:33 288 查看
详细的错误信息如下:

2016-06-28 17:18:13.366 [DefaultQuartzScheduler_Worker-1] ERROR org.quartz.core.JobRunShell:211 - Job group1.job1 threw an unhandled Exception:
java.lang.NullPointerException
at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:45) ~[bin/:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.2.1.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:?]
2016-06-28 17:18:13.374 [DefaultQuartzScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger:2425 - Job (group1.job1 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-2.2.1.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:?]
Caused by: java.lang.NullPointerException
at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:45) ~[bin/:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.2.1.jar:?]


说说我的解决过程:

一、原因很明显:调用了null对象。

根据日志信息,定位到我的Job对象类的指定行,下图的21行:

@Component
public class JobEndConference implements Job {

@Autowired
CallableFsExecCmdProc procExecTask;

@Override
public void execute(JobExecutionContext JEContext) throws JobExecutionException {

JobDataMap map = JEContext.getJobDetail().getJobDataMap();

String meetName = (String) map.get("meetName");

StringBuffer buff = new StringBuffer();
buff.append("bgapi conference ");
buff.append(meetName);
buff.append(" kick all");
// buff.append(ConstantUtil.FS_CMD_TAIL);
// SocketFsTcp4SendCMD.fsSendCommand(buff.toString());
procExecTask.setSendCmd(buff.toString());
Future<Integer> future = StarProxy.executor.submit(procExecTask);
try {
future.get(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
}

}

}


这个对象为空,也就意味着没有通过Spring注解正确的初始化。

确定这个注解的写法是正确的,其他所有的类都是这么写的。

二、那问题在哪里呢?

往上查,看看对这个类的调用情况。

......
JobDetail jobDetail = newJob(JobEndConference.class).withIdentity("job1", "group1").setJobData(dm).build();
......


原因出来了,newJob传入的对象参数并非Spring注解加载的那个对象。

三、解决办法:

方法1. 从Spring的ApplicationContext获取JobEndConference对象。

方法2. 取消JobEndConference的本身和参数的注解,用new初始化。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: