首页 > 其他 > 详细

1.10.4看谁运行的得快

时间:2017-12-03 18:30:53      阅读:220      评论:0      收藏:0      [点我收藏+]

测试如下

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

 

1.10.4看谁运行的得快

原文:http://www.cnblogs.com/edison20161121/p/7954811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!