zoukankan      html  css  js  c++  java
  • 练习三

    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();
        }
    }

  • 相关阅读:
    异步IO数据库队列缓存
    requests.post发送字典套字典
    Git
    Django REST framework
    7. 函数-自定义函数
    6. 小数据池-编码-文件操作
    5. 基本数据结构-集合
    4. 基本数据结构-字典
    3. 基本数据结构-元组
    2. 基本数据结构-列表
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11308894.html
Copyright © 2011-2022 走看看