练习三

复制代码
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();
    }
}
复制代码

 

本文作者:AxeBurner

本文链接:https://www.cnblogs.com/bichen-01/p/11308894.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   AxeBurner  阅读(125)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.