作者Harifucks (疝气)
看板java
标题[J2SE] Java utility timer重设一问
时间Tue Jul 10 20:24:08 2007
public ReceByte(Socket socket) throws IOException
{
this.socket = socket;
timerTask = new TimerTask()
{
public void run()
{
closeConnection();
}
};
timer = new Timer(true);
timer.schedule(timerTask, 1*60*1000);
}
public void checkState()
{
if (checkState == true)
{
//重设timer为60秒
}
}
请问各位先进,以上是小弟的Timer程式码,就是程式执行60秒以後,要把网路连线
关闭。但是假设某一些条件成立後,timer又必须重设为60秒
假设小弟想要重设Timer的时间:
<1>再呼叫一次timer.schedule(timerTask, 1*60*1000);
<2>先呼叫cancel(),再呼叫timer.schedule(timerTask, 1*60*1000);
都发生IllegalStateException,请问如果要重设timer的时间,
要怎麽做呢,请各位先进指导,谢谢。
--
台湾温泉讨论区~www.bearpipi.com.tw
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.31.130.12