zoukankan      html  css  js  c++  java
  • Thread的子类创建线程

    public class Example8_3{
     public static void main(String arg[]){
      Left left=new Left();
      Right right=new Right();
      left.start();
      right.start();
      while(true){
       if(left.n==8||right.n==8)
       System.exit(0);
       
      }
     }
    }
    class Left extends Thread{
     int n=0;
     public void run(){
      while (true){
       n++;
       System.out.printf(" %s","我在左面写字");
                     try{  sleep((int)(Math.random()*100)+100);}
       catch(InterruptedException e){}
      }
     }
    }
    class Right extends Thread{
     int n=0;
     public void run(){
      while(true){
       n++;
       System.out.printf(" %40s","我在右面写字");
       try{ sleep((int)(Math.random()*100)+100);}
        catch(InterruptedException e){}
       
      }
     }
    }

  • 相关阅读:
    F
    D
    J
    M
    H
    L
    Android线程之间的通讯
    Java4Android基础学习之异常
    Java4Android基础学习之接口
    Java4Android基础学习之包与访问权限
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/3149409.html
Copyright © 2011-2022 走看看