线程优先级.Priority()
线程对象.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(); } } }