1 . 優先級表示重要程度或者緊急程度.但是能不能搶到資源也是不一定.
2 . 分配優先級:反映線程的重要或緊急程度
線程的優先級用1~10 表示,1的優先級最低,10的優先級最高,默認值是5
package com.qf.demo3;
/**
* 優先級 : 只能反映 線程 的 中或者是 緊急程度 , 不能決定 是否一定先執行
* setPriority()
* 1~10 1最低 10最高 5是默認值
*/
public class Test { public static void main(String[] args) { MyThread thread = new MyThread("二狗"); thread.setPriority(1); MyThread thread2 = new MyThread("小香菇"); thread2.setPriority(10); MyThread thread3 = new MyThread("小蘑菇"); MyThread thread4 = new MyThread("觀海同志"); thread4.setPriority(3); thread.start(); thread2.start(); thread3.start(); thread4.start(); } } class MyThread extends Thread{ public MyThread(String name) { super(name); } @Override public void run() { for (int i = 0; i < 20; i++) { System.out.println(Thread.currentThread().getName()+"--->"+i); } } }