版权声明:Genius https://blog.csdn.net/weixin_41987706/article/details/91361008
夜光序言:
有一天你会明白,人不能太善良,因为人们只会挑软柿子捏,如果事事都太大度和宽容,别人也不会感激你,有时候应该适当的有点脾气,对待有些人真不能太温柔和忍耐,因过分善良会让我们丢失自己的价值和尊严,过分善良也是一种傻。
正文:线程的优先级及线程的调度
线程优先级的概念
线程优先级的设置
有关线程优先级的程序示例
主类(测试类)—testThread
程序运行结果及分析
// 夜光
class MyThread1 extends Thread
{
public void run()
{
for(int i=0;i<=10000;i++)
{ System.out.print("<Min"+i+">");
}
}
}
class MyThread2 extends Thread
{
public void run()
{
for(int i=0;i<=10000;i++)
{ System.out.print("<Max"+i+">");
}
}
}
public class testThread
{
public static void main(String args[])
{
//创建两个线程对象
MyThread1 t1=new MyThread1();
MyThread2 t2=new MyThread2();
//设置两个线程的优先级
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
//启动两个线程
t1.start();
t2.start();
}
}