zoukankan      html  css  js  c++  java
  • 1.10.4看谁运行的得快

    测试如下

    package com.cky.prioritydemo;
    
    /**
     * Created by edison on 2017/12/3.
     */
    public class ThreadA extends  Thread{
        private int count =0;
        public int getCount() {
            return count;
        }
        @Override
        public void run() {
            super.run();
            while(true) {
                count++;
            }
        }
    }
    package com.cky.prioritydemo;
    
    /**
     * Created by edison on 2017/12/3.
     */
    public class ThreadB extends Thread{
        private int count =0;
        public int getCount() {
            return count;
        }
        @Override
        public void run() {
            super.run();
            while(true) {
                count++;
            }
        }
    }
    package com.cky.prioritydemo;
    
    /**
     * Created by edison on 2017/12/3.
     */
    public class TestAB {
        public static void main(String[] args) {
            try {
                ThreadA thA = new ThreadA();
                thA.setPriority(Thread.NORM_PRIORITY -3);
                thA.start();
                ThreadB thB = new ThreadB();
                thB.setPriority(Thread.NORM_PRIORITY +3);
                thB.start();
                Thread.sleep(2000);
                thA.stop();
                thB.stop();
                System.out.println("a="+thA.getCount());
                System.out.println("b="+thB.getCount());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    a=1428639097
    b=1429717263
  • 相关阅读:
    react特点和创建虚拟DOM
    vue的keep-alive
    JavaScript-事件委托
    vue-router参数传递
    js常用的字符串处理
    vue-vuex
    vue-组件
    vue-父子组件传值
    堆和栈
    js-深拷贝浅拷贝
  • 原文地址:https://www.cnblogs.com/edison20161121/p/7954811.html
Copyright © 2011-2022 走看看