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
  • 相关阅读:
    010_STM32CubeMXADC
    009_STM32CubeMXPWM
    008_STM32CubeMX定时器中断
    007_STM32CubeMX外部中断
    006_STM32CubeMX按键输入
    005_STM32CubeMX串口
    004_STM32CubeMX官方例程
    003_STM32CubeMX点灯
    002_STM32CubeMX配置基础工程
    006_word发表博客到博客园中
  • 原文地址:https://www.cnblogs.com/edison20161121/p/7954811.html
Copyright © 2011-2022 走看看