1 package com.climbdemo; 2 /** 3 * 实用类 4 * @author jjit 5 * 6 */ 7 public class ClimbDemo extends Thread { 8 public int num; 9 private int time; 10 11 public ClimbDemo(String name,int time,int kil) { 12 super(name); 13 this.num = kil*1000/100; 14 this.time = time; 15 } 16 public void run() { 17 while(num>0) { 18 try { 19 Thread.sleep(this.time); 20 System.out.println(Thread.currentThread().getName()+"爬完100米"); 21 } catch (InterruptedException e) { 22 e.printStackTrace(); 23 } 24 num--; 25 } 26 System.out.println(Thread.currentThread().getName()+"到达终点!"); 27 } 28 }
1 package com.climbdemo; 2 /** 3 * 实现类 4 * @author jjit 5 * 6 */ 7 public class TestThread { 8 public static void main(String[] args) { 9 ClimbDemo zs = new ClimbDemo("张三",800,1); 10 ClimbDemo ls = new ClimbDemo("李四",1200,1); 11 ClimbDemo ww = new ClimbDemo("王五",1000,1); 12 zs.start(); 13 ls.start(); 14 ww.start(); 15 } 16 }