开发者社区> 问答> 正文

启动一个定时任务就报错了 ?报错

但是任务还是继续跑着

 2016-3-11 10:36:15 org.quartz.core.ErrorLogger schedulerError
严重: Unable to notify JobListener(s) of Job that was executed: (error will be ignored). trigger= group2.guanbi job= group2.job2
org.quartz.SchedulerException: JobListener 'dummyJobListenerName' threw exception: null [See nested exception: java.lang.NullPointerException]
    at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1987)
    at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:340)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:224)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
    at test1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)
    at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1985)
    ... 3 more

下面是报错类的代码

 public class HelloJobListener implements JobListener {
    public static final String LISTENER_NAME = "dummyJobListenerName";
    @Override
    public String getName() {
        // TODO Auto-generated method stub
        return LISTENER_NAME;
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        String jobName = context.getJobDetail().getKey().toString();
        System.out.println("jobToBeExecuted");
        System.out.println("Job : " + jobName + " is going to start...");
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        System.out.println("jobExecutionVetoed");
    }



    @Override
    public void jobWasExecuted(JobExecutionContext context,
            JobExecutionException jobException) {
        System.out.println("jobWasExecuted");

        String jobName = context.getJobDetail().getKey().toString();
        System.out.println("Job : " + jobName + " is finished...");

        if (!jobException.getMessage().equals("")) {
            System.out.println("Exception thrown by: " + jobName
                + " Exception: " + jobException.getMessage());
        }
    }

}

展开
收起
爱吃鱼的程序员 2020-06-23 14:10:25 1205 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    JobListener'dummyJobListenerName'threwexception:null[Seenestedexception:java.lang.NullPointerException]
    抛出的是空指针异常,建议断点跟进去看看哪里的get方法报错。

    Causedby:java.lang.NullPointerException
    attest1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)

    第37行是什么?

    关于spring和quartz的配置和使用,可参考:http://git.oschina.net/wangkang/llsfw

    希望能够帮到你.

    断点,attest1.HelloJobListener.jobWasExecuted(HelloJobListener.java:37)第37行报空指针。

    StringjobName=context.getJobDetail().getKey().toString();

    这行空指针错误,加个点点看看你的context是不是null,或者context.getJobDetail()是不是null

    2020-06-23 14:10:43
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载