线程的休眠

/*线程的休眠:Thread.sleep()*/


class MyThread6 implements Runnable{
public void run(){
for(int i=0; i<10; i++){
System.out.println(Thread.currentThread().getName()+"运行:"+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}
public class ThreadSleep {


public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread6 my6 = new MyThread6();
Thread th = new Thread(my6,"线程A");
th.start();
}


}


/*
运行结果:(每隔1s输出一个)
线程A运行:0
线程A运行:1
线程A运行:2
线程A运行:3
线程A运行:4
线程A运行:5
线程A运行:6
线程A运行:7
线程A运行:8
线程A运行:9
*/

你可能感兴趣的:(线程)