Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » Java与OOP初步  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:请教Thread类的join()方法的涵义 [Re:cxp108]
tianningsi





发贴: 9
积分: 0
于 2007-02-08 20:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢cxp108,
以下是测试代码:
/**
* Date:2007-2-7
* JoinTest
* @author Mao
* @version 1.0
*/

public class JoinTest {
  public static void main(String[] args)throws Exception {
    Counter counter1 = new Counter();
    Counter counter2 = new Counter();
    Counter counter3 = new Counter();
    
    counter1.start();
    counter1.join(); //等待counter1结束

    counter2.start();
    counter2.join();

    counter3.start();
  }
}

class Counter extends Thread{
  private int count;

  public void run(){
    while (true){
      System.out.println(this.getName()+(++count));
      try{
        sleep(300);
      }catch(InterruptedException ex){
      }
      if(count == 12)
        return;
    }
  }
}




一个程序员的奋斗历程

话题树型展开
人气 标题 作者 字数 发贴时间
15406 请教Thread类的join()方法的涵义 tianningsi 29 2007-02-06 16:50
13466 Re:请教Thread类的join()方法的涵义 cxp108 111 2007-02-08 10:14
13484 Re:请教Thread类的join()方法的涵义 tianningsi 683 2007-02-08 20:46
13429 Re:请教Thread类的join()方法的涵义 gumuyang 74 2007-02-09 08:57
13410 Re:请教Thread类的join()方法的涵义 tianningsi 127 2007-02-09 10:28
13505 Re:请教Thread类的join()方法的涵义 gumuyang 165 2007-02-09 14:47
13890 Re:请教Thread类的join()方法的涵义 tianningsi 126 2007-02-09 18:20

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923