作为回答的@MarcoS
我发现超时不提高,如果方法是锁定的东西而不是释放CPU时间到定时器。 然后Timer不能启动新的线程。 因此,我立即改变了一下开始线程,睡在线程内。
InterruptTimerTaskAddDel interruptTimerTask = new InterruptTimerTaskAddDel(
Thread.currentThread(),timeout_msec);
timer.schedule(interruptTimerTask, 0);
/*
* A TimerTask that interrupts the specified thread when run.
*/
class InterruptTimerTaskAddDel extends TimerTask {
private Thread theTread;
private long timeout;
public InterruptTimerTaskAddDel(Thread theTread,long i_timeout) {
this.theTread = theTread;
timeout=i_timeout;
}
@Override
public void run() {
try {
Thread.currentThread().sleep(timeout);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace(System.err);
}
theTread.interrupt();
}
}