码迷,mamicode.com
首页 > 编程语言 > 详细

线程优先级.Priority()

时间:2018-09-02 12:32:23      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:ati   循环   启动   作用   []   static   线程优先级   sys   stat   

线程对象.Priority(),线程优先级1-10,10优先级最高。此功能比较鸡肋,不起作用。了解即可

以下案例:循环输出加减乘除,除优先级最高

//MyThread线程
class MyThread extends Thread {
    String name;
    String sign;

    //Alt+Insert,Constructor 快速创建MyThread线程的构造方法
    public MyThread(String name, String sign) {
        this.name = name;
        this.sign = sign;
    }

    public void run() {//线程要执行的任务
        System.out.println(name + ":" + sign);
    }
}

public class Demo {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            MyThread m1 = new MyThread("加", "+");//调用构造方法
            MyThread m2 = new MyThread("减", "-");
            MyThread m3 = new MyThread("乘", "×");
            MyThread m4 = new MyThread("除", "÷");
//线程优先级1-10,10优先级最高
            m1.setPriority(1);
            m2.setPriority(4);
            m3.setPriority(7);
            m4.setPriority(10);
//启动线程
            m1.start();
            m2.start();
            m3.start();
            m4.start();

        }
    }
}

 

线程优先级.Priority()

标签:ati   循环   启动   作用   []   static   线程优先级   sys   stat   

原文地址:https://www.cnblogs.com/xixixing/p/9573325.html

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