线程的串行化

作者在 2010-05-23 19:24:37 发布以下内容
public class TestJoin {    
    public static void main(String args[]){
        MyRunner r = new MyRunner();
        Thread t = new Thread(r);
        t.start();
        try{
            t.join();
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        for(int i=0;i<50;i++){
            System.out.println("主线程:" + i);
        }
    }
}

class MyRunner implements Runnable {
    public void run() {
        for(int i=0;i<50;i++) {
            System.out.println("SubThread: " + i);
        }
    }
}
线程 | 阅读 809 次
文章评论,共0条
游客请输入验证码
浏览275889次