java线程学习

来源:互联网 发布:java线程超时控制 编辑:程序博客网 时间:2024/05/16 07:20
//线程练习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");}}}}

0 0
原创粉丝点击