class MyThread implements Runnable{
 int count;
 String thrdName; MyThread(String name){
  count = 0;
  thrdName = name;
 }//进入线程
 public void run(){
   System.out.println(thrdName + " starting.");
   try{
      do{
         Thread.sleep(500);
          System.out.println("In " + thrdName + " count is "+count);
         count++;
      }while(count < 10);
   }
    catch(InterruptedException e){
        System.out.println(thrdName + " interrupted.");
    }
    System.out.println(thrdName + " terminating.");
  }
}class UseThreads{
   prublic static void main(String arg[]){
   System.out.println("Main thread starting.");
   
    MyThread mt = new MyThread("Child @1");//创建新线程    Thread newThrd = new Thread(mt);//创建对象的一个线程    newThrd.start();//开始运行线程
    
    do{
       System.out.print("=");
       try{
          Thread.sleep(100);
       }
       catch(InterruptedExcption e){
            System.out.printlin("Main thread interrupted.");
       }
    }while(mt.count != 10);
    System.out.println("Main thread ending.");
  }
}这是一个基本的线程实例,没有经过测试。