If yours is a single thread, it is easy.Thread.currentThread().sleep(1000);
Thread.sleep(long [,int]); 进行设置等待的时间
可以看看线程的讲解啊,java有提供这样的方法.
Anywhere in a method regardless whether the class is a Thread/Runnable or not:try{ Thread.sleep(1000);//1000ms = 1sec }catch(InterruptedException e){ }
while(!stop) {
System.out.println("ok");
try {
wait(2000);
} catch(InterruptedException e) {
System.err.println("Interrupted");
}
}
}
进行设置等待的时间
Thread.sleep(1000);//1000ms = 1sec
}catch(InterruptedException e){
}