多线程Test1
Posted zhangchuanfeng1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多线程Test1相关的知识,希望对你有一定的参考价值。
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 }
以上是关于多线程Test1的主要内容,如果未能解决你的问题,请参考以下文章