码迷,mamicode.com
首页 > 其他好文 > 详细

1.10.4看谁运行的得快

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

标签:art   iso   catch   com   override   dex   pack   span   ace   

测试如下

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看谁运行的得快

标签:art   iso   catch   com   override   dex   pack   span   ace   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!