Java蜘蛛人 欢迎大家

欢迎大家 来到我的blog , 如果我身边的朋友 有什么不懂可以直接来问我 我会细心的帮助你的. 如果网络上的朋友有什么不懂的 可以加我Java蜘蛛人 QQ48187537
posts - 54, comments - 192, trackbacks - 0, articles - 1

多线程

Posted on 2008-02-06 02:11 Java蜘蛛人 --郑成桥 阅读(264) 评论(0)  编辑  收藏
public class Test extends Thread {
 
 private String tran;
 
 
 public Test(String tran)
 {
  this.tran=tran;
 }
 
 
 @Override
 public void run() {
  try {
    if(tran.equals("tran"))
     show();
    else
     show1();
   
  } catch (Exception e) {
   e.printStackTrace();
   // TODO: handle exception
  }
 
 }
 public void show()throws Exception
 {
  
  for(int i=100;i>0;i--)
  {
  System.out.println("show        "+i);
   if(i==50)
    Thread.sleep(200);
   
  }
 }
 
 public void show1()throws Exception
 {
  for(int i=100;i>0;i--)
  {
  System.out.println("show1       "+i);
   if(i==50)
    Thread.sleep(200);
  }
 }
 
 public static void main(String[] args) {
  
  Thread show=new Test("tran");
  Thread show1=new Test("tran2");
  
  show.start();
  
  show1.start();
  
 }
}

只有注册用户登录后才能发表评论。


网站导航: