
package zuoYe02;
public class Person implements Runnable {
private int time;
// 自己定义有十个一百米 每跑一百米,则减一 为0时则到达终点
public int count = 10;
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public Person(int time) {
super();
this.time = time;
}
@Override
public void run() {
// 程序开始运行
// boolean boo = false;
while (true) {
if (count == 0) {
System.out.println(Thread.currentThread().getName() + "到达终点");
// boo = true;
return;
}
--count;
System.out.println(Thread.currentThread().getName() + "爬完100米!");
try {
Thread.sleep(this.time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
package zuoYe02;
public class TestPersonThread {
public static void main(String[] args) {
Person y = new Person(500);
Person o = new Person(900);
Thread t1 = new Thread(y,"年轻人");
Thread t2 = new Thread(o,"老年人");
t1.start();
t2.start();
}
}
