欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java.lang.IllegalArgumentException: Non-positive period. 博客分类: Exception java.lang.IllegalArgumentException: Non-positive period.ExceptionTimer 

程序员文章站 2024-03-14 23:57:17
...
出错代码:
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);