在某个地方保留对计时器的引用,并使用:
timer.cancel();timer.purge();
停止所做的一切。您可以将此代码放在正在执行的任务中,
static int以计算您经过的次数,例如
private static int count = 0;public static void run() { count++; if (count >= 6) { timer.cancel(); timer.purge(); return; } ... perform task here ....}


