package com.test.test06; public class TestThread01 extends Thread{ @Override public void run() { //输出1-10 for(int i=1;i<=10;i++) { System.out.println(i); } } } class TestThread02 extends Thread{ @Override public void run() { //输出20-30 for(int i=20;i<=30;i++) { System.out.println(i); } } } class Test{ public static void main(String[] args) { //创建两个子线程,让这两个子线程争抢资源 TestThread01 t1 = new TestThread01(); t1.setPriority(10); //优先级别高 t1.start(); TestThread02 t2 = new TestThread02(); t2.setPriority(1); //优先级别低 t2.start(); } /* 1 2 3 4 5 6 7 8 9 10 20 21 22 23 24 25 26 27 28 29 30*/ }
java设置线程优先级Priority用法
最新推荐文章于 2024-06-15 01:05:55 发布