展开全部
可以使用sleep()方法。
sleep()方法拥有一个参数,它控制睡眠的长短,以毫秒计算。sleep()方法会抛出InterruptedException,所以一62616964757a686964616fe58685e5aeb931333361313866定在try-catch块里面使用它。
示例代码如下:public class A implements Runnable{
int i = 0;
public static void main(String[] args){
A a1 = new A();
A a2 = new A();
a1.run();
a2.run();
}
public void run(){
while(++i <= 100){
System.out.println(i);
try{
Thread.sleep(50);
}catch(Exception e){
e.printStackTrace();
}
}
}
}
注意,sleep()方法并不保证线程醒来后进入运行,只能保证它进入就绪状态。