java.lang.IllegalArgumentException: Non-positive period.

阅读更多
出错代码:
timer = new Timer();
timer.schedule(new MQConnectionTimerTask(), new Date(), 0);


错误信息:
严重: Exception sending context initialized event to listener instance of class com.queuemanagerlistener.listener.MQConnectionStatusListener
java.lang.IllegalArgumentException: Non-positive period.
 at java.util.Timer.schedule(Timer.java:221)
 at ngbss.iac.queuemanagerlistener.listener.MQConnectionStatusListener.contextInitialized(MQConnectionStatusListener.java:72)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)


原因:
在项目中用到了TimerTask时间调度器,如果调度间隔时间为0的时候,则会发生错误: java.lang.IllegalArgumentException: Non-positive period.,必须要设置大于0 的数。

解决方案:
调度间隔时间值确保大于0,如:
timer = new Timer();
timer.schedule(new MQConnectionTimerTask(), new Date(), 1 * 60 * 1000);

你可能感兴趣的:(Non-positive,period.,Exception,Timer)