threadprioritydemo.java

来自「学习参考,java基本语法练习,包括一些常用的技巧」· Java 代码 · 共 31 行

JAVA
31
字号
//线程调度演示
public class ThreadPriorityDemo
{
	public static void main(String args[]) 
	{
		Thread t1=new MyThread("线程1:");
		t1.setPriority(Thread.MIN_PRIORITY); //设置优先级为最小
		t1.start( );
		Thread t2=new MyThread("线程2:");
		t2.setPriority(Thread.NORM_PRIORITY); //设置优先级为普通
		t2.start( );
		Thread t3=new MyThread("线程3:");
		t3.setPriority(Thread.MAX_PRIORITY); //设置优先级为最大
		t3.start( );
	}
}
class MyThread extends Thread 
{
	String strMsg;
	MyThread (String message) 
	{
		this.strMsg = message;
	}
	public void run() 
	{
		for ( int i=0; i<3; i++ )
			//获得线程的优先级
			System.out.println(strMsg+getPriority()); 
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?