package 练习;
/*
线程的优先级: 只是提高执行的概率
Thread.MAX_PRIORITY----》10
Thread.MIN_PRIORITY-----》1
MIN_PRIORITY-----》5
数字越大优先级越高 1-10之间;
获取线程的优先级 设置当前线程的优先级:oushu.setPriority(Thread.MAX_PRIORITY);
*/
public class ThreadDiaoDu {
public static void main(String[] args) {
oushu2 oushu = new oushu2();
oushu.setPriority(Thread.MAX_PRIORITY);
oushu.start();
//当前线程 Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
jishu2 jishu = new jishu2();
jishu.setPriority(Thread.MIN_PRIORITY);
jishu.start();
System.out.println(jishu.getPriority());
}
}
class oushu2 extends Thread
{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
if (i%2==0) {
Thread.currentThread().setName("偶数");
System.out.println(Thread.currentThread().getName()+i);
}
}
}
}
class jishu2 extends Thread
{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
if (i%2!=0) {
Thread.currentThread().setName("奇数");
System.out.println(Thread.currentThread().getName()+i);
}
}
}
}
thread类的线程优先级
最新推荐文章于 2024-04-01 15:53:31 发布