ScheduledExecutorService only runs once

旧街凉风 提交于 2019-12-04 06:59:35

Wrap run code with try catch

Just a guess: An exception is being thrown. A ScheduledExecutorService halts silently if it encounters an Exception.

The run method’s code should always be surrounded by a try-catch to handle and absorb any thrown Exception.

 @Override
 public void run() {
    try {  // Let no Exception reach the ScheduledExecutorService.
        Date date = new Date(System.currentTimeMillis());
        System.out.println("Running scheduled update check " + date.toString());
        updateSubscriberService.checkForUpdates();
    } catch ( Exception e ) {
        System.out.println( "ERROR - unexpected exception" );
    }
}

Stub out run method

Take baby steps. Begin with a run method that does nothing but a System.out.println.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!