使用以下命令设置重复任务:
//Declare the timerTimer t = new Timer();//Set the schedule function and ratet.scheduleAtFixedRate(new TimerTask() { @Override public void run() { //Called each time when 1000 milliseconds (1 second) (the period parameter) }},//Set how long before to start calling the TimerTask (in milliseconds)0,//Set the amount of time between each execution (in milliseconds)1000);如果您想取消任务,只需调用
t.cancel()这里
t就是您的
Timer对象
并且您还可以检查答案下方的评论,他们已经提供了有关此内容的简短信息。



