在运行下面这个测试程序的时候,用鼠标点击一下控制台界面后程序就暂停了。然后点击键盘任意键即可重新运行,不知道能不能让控制台的程序不暂停?先谢谢。
import java.util.*; // Java Util classes
import java.lang.*;public class TimerTest3
{
Timer timer;
public TimerTest3(int seconds)
{
timer = new Timer();
timer.scheduleAtFixedRate(new PubTimerTask(), new Date(),seconds*1000);
}
public static void main(String args[])
{
new TimerTest3(1);
System.out.println("Task scheduled.");
} class PubTimerTask extends TimerTask
{
public void run()
{
System.out.println("Scan File Begin :" + Calendar.getInstance().getTime().toString());
}
}
}
import java.util.*; // Java Util classes
import java.lang.*;public class TimerTest3
{
Timer timer;
public TimerTest3(int seconds)
{
timer = new Timer();
timer.scheduleAtFixedRate(new PubTimerTask(), new Date(),seconds*1000);
}
public static void main(String args[])
{
new TimerTest3(1);
System.out.println("Task scheduled.");
} class PubTimerTask extends TimerTask
{
public void run()
{
System.out.println("Scan File Begin :" + Calendar.getInstance().getTime().toString());
}
}
}
import java.lang.*;public class TimerTest3 extends Thread
{
Timer timer;
private int seconds = 1;
public TimerTest3(int seconds)
{
this.seconds = seconds;
} public void run()
{
timer = new Timer();
timer.scheduleAtFixedRate(new PubTimerTask(), new Date(),seconds*1000);
}
class PubTimerTask extends TimerTask
{
public void run()
{
System.out.println("Scan File Begin :" + Calendar.getInstance().getTime().toString());
}
}
}//下面是运行线程的程序,你只要运行它就可以了public class RunTimerTest3
{ /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Thread timerTest3 = new TimerTest3(1);
timerTest3.run();
}}