public class 测试2 {
public static void main(String[] args) {
Runnable t = new Runnable(){
private int tick = 100; //将tick调成成员方法 并私有
public void run(){
while(true){
if(tick>0)
System.out.println(Thread.currentThread().getName()+" zz_sale: "+tick--);
}
}
};
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
Thread t3 = new Thread(t);
Thread t4 = new Thread(t);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |