详细的错误信息如下:
-- ::13.366 [DefaultQuartzScheduler_Worker-] ERROR org.quartz.core.JobRunShell: - Job group1.job1 threw an unhandled Exception:
java.lang.NullPointerException
at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:) ~[bin/:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:) [quartz-2.2..jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:) [quartz-2.2..jar:?]
-- ::13.374 [DefaultQuartzScheduler_Worker-] ERROR org.quartz.core.ErrorLogger: - Job (group1.job1 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:) [quartz-2.2..jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:) [quartz-2.2..jar:?]
Caused by: java.lang.NullPointerException
at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:) ~[bin/:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:) ~[quartz-2.2..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(, 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初始化。