java @Schedule在系统时间改变了两个小时后停止工作

时间:2014-05-30 08:44:28

标签: java time cron ntp

我有一个带有标记为@Schedule的cron作业的java应用程序,java版本是

java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

我在jboss7.1上运行应用程序

我们已经将机器的系统时间改了两个小时,基本上没有安装ntp,我们安装它来纠正时间,因为它已经过时了。

之后,cron作业停止工作。即使我重新启动jboss也无济于事。

日志中也没有错误可能表明出现了问题。我在代码中添加的System.out也没有写入输出,所以我认为代码根本没有执行。

我的cron工作:

@Singleton
@Lock(LockType.READ)
public class InstanceUpdater {

@EJB
FourPmInstanceBL fourPmInstanceBL;
@EJB
VMWareHandler vmWareHandler;
@EJB
PuppetHandler puppetHandler;
@EJB
FourPmInstanceHandler fourPmInstanceHandler;
@Inject
private Event<InstanceStatusChangeEvent> instanceStatusChangeEvent;

@Schedule(hour="*", minute="*", second="*/10")
public void startTimer() {
    System.out.println(">>>>>>>>> Instance updater started " + new Date());

    for (FourPmInstance instance : fourPmInstanceBL.getInstanceToProcess()) {

        Date currentTime = new Date();
        boolean canAcceptInstance = true;
        //neaded 30 sec delay betwen acceptance because of vmware cocnurent template reading problem.
        if(instance.getProcessAt() != null){
            canAcceptInstance = currentTime.after(instance.getProcessAt());
            System.out.println(">>>>>>>>> Instance can be accepted: " + canAcceptInstance);
            System.out.println(">>>>>>>>> Proces instance at " + instance.getProcessAt());
        }

        //Long instancesInProgres = fourPmInstanceBL.getCountinProgres();

        if (instance.getStatus().equals(InstanceStatus.NEW)) {

            if(canAcceptInstance){
                System.out.println(">>>>>>>>> Instance accepted " + instance.getName());
                try {
                    instanceStatusChangeEvent.fire(new InstanceStatusChangeEvent(instance,InstanceStatus.IN_PROGRESS));
                    fourPmInstanceHandler.registerNewInstance(instance);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    instanceStatusChangeEvent.fire(new InstanceStatusChangeEvent(instance,InstanceStatus.ERROR));
                }
            }

        } else {

            try {
                instanceStatusChangeEvent.fire(new InstanceStatusChangeEvent(instance,InstanceStatus.IN_PROGRESS));
                System.out.println(">>>>>>>>> Instance update " + instance.getName());
                fourPmInstanceHandler.updateHardwareAndLicence(instance);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                instanceStatusChangeEvent.fire(new InstanceStatusChangeEvent(instance,InstanceStatus.ERROR));
            } 


        }


    }



}    

}

0 个答案:

没有答案