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

    package zuoYe03;
    
    public class Running implements Runnable {
    
        // 一个选手跑100米 10个选手才跑1000米
        public static int count = 0;
    
        @Override
        public void run() {
            // TODO Auto-generated method stub
    
            synchronized (this) {
    
                System.out.println(Thread.currentThread().getName() + "拿到了接力棒!");
    
                for (int i = 1; i <= 10; i++) {
    
                    System.out.println(Thread.currentThread().getName() + "跑了" + 10 * i + "米!");
    
                }
                ++count;
                if (count == 10) {
    
                    System.out.println("恭喜团队跑满1000米!");
                    return;
                } else {
    
                    System.out.println("还未跑完,团队仍需努力!");
                    return;
                }
    
            }
    
        }
    
    }
    package zuoYe03;
    
    public class Test {
    
        public static void main(String[] args) {
            
            Running r = new Running();
            
            for (int i = 1; i <= 10; i++) {
                
            
            Thread t = new Thread(r,i+"号选手");
            
            
            t.start();
            }
    
            
        }
    }

    实现结果:

  • 相关阅读:
    AE旋转
    AE2
    AE1
    面试
    TS 基础数据类型
    vue-cli结构介绍
    js异步加载的5种方式
    slot 插槽的使用
    使用组件的细节点
    Vue 条件渲染
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11312483.html
Copyright © 2011-2022 走看看