English 中文(简体)
预定任务中未预见到的错误
原标题:Unexpected error occurred in scheduled task

我尝试在我的春季-波波特申请中开展一项预定任务,使用默认<代码>> 申请表Config——我只添加了通知编号@EnableSstaling<>/code>,并根据以下代码样本将这一类别与将要安排的方法混为一谈:

@Component 
public class Task { 

 @Scheduled(cron ="*/10 * * * * *")
  public void init() {
    System.out.println("QuartzConfig initialized.");
    System.out.println(callService());
  }

  private String callService() {
    String urlService = "https://www.google.com";
    GetMethod method = new GetMethod(urlService );
    String response = "";
    try {
        client.executeMethod(method);
        response = method.getResponseBodyAsString();
    } catch (IOException e) {
       e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
    return response;
  }
}

然而,当任务被指定时,该方法<代码>--------------------------------------------------

java.lang.NullPointerException: null

这显然使我感到悲痛。

问题回答

由于我发表的评论意见,我解决了后面加上的排外法。

 public Task(){     
          client = new HttpClient();
          client.getParams().setParameter("http.useragent", "Bacon/1.0");
    }

页: 1 Ngwenya





相关问题
Gearman Scheduler

Anybody have experience or thoughts on a scheduler to couple with a persistent Gearman queue? Obviously there s crontab available, but i d like some more functionality. We re looking at Java Quartz. ...

Import Quartz DLL in C# VIsual Studio

I m in need for the Quartz DLL , I ve downloaded all the source and everything and there is the Quartz.dll and Common.Logging.dll files, but I don t know how to use them in my own applications. Can ...

Is it possible to run a cron job in a web application?

In a java web application (servlets/spring mvc), using tomcat, is it possible to run a cron job type service? e.g. every 15 minutes, purge the log database. Can you do this in a way that is ...