while (true) {
Thread.sleep(1000);//等待1S
System.out.println("----------");
}
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Test {
public static void main(String[] args) {
Timer t=new Timer();
t.schedule(new TimerTask(){
@Override
public void run() {
System.out.println("hello world!");
}
},new Date() ,1000);//每隔1秒输出
}
}