java——多线程的实现

package test;

class TestThread extends Thread{
    
public void run()
{
    for(int n=0;n<3;n++)
    { try{Thread.sleep(1000);}//线程休息毫秒
    catch(InterruptedException e){e.printStackTrace();}
    System.out.println("n="+n);    
    }

}

}
package test;

public class Testlianxithread {

    public static void main(String[] args) {

        TestThread tt = new TestThread();
        tt.start();// 启动多线程
        TestThread tt2 = new TestThread();
        tt2.start();
        TestThread tt3 = new TestThread();
        tt3.start();

    }

}

输出结果为每隔1000毫秒输出

posted on 2015-12-20 11:28  Chen_s  阅读(137)  评论(0编辑  收藏  举报

导航