Tag Archives: Quartz: ERROR threw an unhandled Exception

Quartz: ERROR threw an unhandled Exception [How to Solve]

The detailed error message is as follows:

 1  2016 - 06 - 28  . 17 : 18 is : 13.366 [DefaultQuartzScheduler_Worker- . 1 ] ERROR org.quartz.core.JobRunShell: 211 - the Job group1.job1 threw AN Unhandled Exception: 
 2  java.lang.NullPointerException
 3      AT com.starunion.java. service.timer.JobEndConference.execute(JobEndConference.java: 45 ) ~[bin/:? ]
 4      at org.quartz.core.JobRunShell.run(JobRunShell.java: 202 ) [quartz- 2.2 . 1 .jar:? ]
 5     org.quartz.simpl.SimpleThreadPool $ WorkerThread.run AT (SimpleThreadPool.java: 573 ) [quartz- 2.2 . . 1 .jar :? ]
 6  2016 - 06 - 28  . 17 : 18 is : 13.374 [DefaultQuartzScheduler_Worker- . 1 ] ERROR org.quartz .core.ErrorLogger: 2425 - Job (group1.job1 threw an exception.
 7  org.quartz.SchedulerException: Job threw an unhandled exception.
 8      at org.quartz.core.JobRunShell.run(JobRunShell.java: 213 ) [quartz- 2.2 . 1 .jar:?]
 9      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java: 573 ) [quartz- 2.2 . 1 .jar:? ]
 10  Caused by: java.lang.NullPointerException
 11      at com.starunion.java.service .timer.JobEndConference.execute(JobEndConference.java: 45 ) ~[bin/:? ]
 12      at org.quartz.core.JobRunShell.run(JobRunShell.java: 202 ) ~[quartz- 2.2 . 1 .jar:?]

Talk about my solution process:

1. The reason is obvious: the null object is called.

According to the log information, locate the specified line of my Job object class, line 21 in the following figure:

1  @Component
2  public  class JobEndConference implements Job {
3  
4      @Autowired
5      CallableFsExecCmdProc procExecTask;
6  
7      @Override
8      public  void execute(JobExecutionContext JEContext) throws JobExecutionException {
9  
10          JobDataMap map = JEContext.getJobDetail().getJobDataMap();
11  
12          String meetName = (String) map. get ( " meetName " );
13  
14          StringBuffer buff = newStringBuffer();
15          buff.append( " bgapi conference " );
16          buff.append(meetName);
17          buff.append( " kick all " );
18          // buff.append(ConstantUtil.FS_CMD_TAIL); 
19          20          // SocketFsTcp4SendCMD.fsSendCommand(buff.toString()); 
21          procExecTask.setSendCmd(buff.toString());
22          Future<Integer> future = StarProxy.executor.submit(procExecTask);
23          try {
24              future. get ( 5000, TimeUnit.MILLISECONDS);
25          } catch (InterruptedException | ExecutionException | TimeoutException e) {
26              e.printStackTrace();
27          }
28  
29      }
30  
31 }

This object is empty, which means that it has not been properly initialized through Spring annotations.

Make sure that this annotation is written correctly, all other classes are written this way.

2. Where is the problem?

Check up to see how this class is called.

. 1  ......
 2 the JobDetail jobDetail = newJob (JobEndConference. Class ) .withIdentity ( " the jobs that job1 " , " named group1 " ) .setJobData (DM) .build ();
 . 3 ......

The reason is that the object parameter passed in by newJob is not the object loaded by the Spring annotation.

3. Solution:

Method 1. Obtain the JobEndConference object from Spring’s ApplicationContext.

Method 2. Cancel the annotation of JobEndConference itself and parameters, and initialize with new.