//线程练习
public class ThreadTest {
public static void main(String[] args){
MyThread mt=new MyThread();
mt.start();
for(int i=0;i<10;i++){
try{
Thread.sleep(1000);
System.out.println("主方法睡觉"+i);
}
catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("第"+i+"线程启动");
}
}
static class MyThread extends Thread{
public void run(){
for(int i=0;i<10;i++){
try{
Thread.sleep(1000);
System.out.println("睡觉2");
}
catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("第"+i+" MyThread");
}
}
}
}
java线程学习
最新推荐文章于 2022-07-23 00:05:47 发布