public class TestThread {
public static void main(String args[]) {
Thread1 t1 =new Thread1();
Thread2 t2 =new Thread2();
t1.start();
Thread t =new Thread(t2);
t.start();
for(int i=1;i<=100;i++){
System.out.println("主线程:"+i);
}
}
}
//方式一
class Thread1 extends Thread{
public void run(){
for(int i=1;i<=100;i++){
System.out.println("线程1:"+i);
}
}
}
//方式二
class Thread2 implements Runnable{
public void run(){
for(int i=1;i<=100;i++){
System.out.println("线程2:"+i);
}
}
}线程的两种实现方式
最新推荐文章于 2024-10-17 18:11:16 发布
2199

被折叠的 条评论
为什么被折叠?



