javaSE之多线程之优先级

    科技2025-01-17  4

    package state; public class TestPriority { //主线程默认优先级 public static void main(String[] args) { System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority()); MyPriority priority = new MyPriority(); Thread t1 = new Thread(priority); Thread t2 = new Thread(priority); Thread t3 = new Thread(priority); Thread t4 = new Thread(priority); t1.start(); t2.setPriority(10); t2.start(); t3.setPriority(8); t3.start(); t4.setPriority(7); t4.start(); } } class MyPriority implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority()); } }
    Processed: 0.014, SQL: 8