![]()
![]()
package cn.climb;
public class ClimbThread implements Runnable{
private int num;
private int time;
public ClimbThread(int num, int time) {
super();
this.num = num;
this.time = time;
}
public ClimbThread() {
super();
}
@Override
public void run() {
for(int i = 0;i<10;i++) {
String ss = Thread.currentThread().getName();
if(i ==9) {
System.out.println(ss+"到达终点");
return;
}
System.out.println(ss+"在爬第"+(i+1)+"个100米");
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
****************************************************
package cn.climb;
public class Main {
public static void main(String[] args) {
ClimbThread old = new ClimbThread(10,2000);
ClimbThread young = new ClimbThread(10,1000);
Thread oldman = new Thread(old,"老年人");
Thread youngman = new Thread(young,"年轻人");
oldman.start();
youngman.start();
}
}
![]()