⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadprioritydemo.java

📁 学习参考,java基本语法练习,包括一些常用的技巧
💻 JAVA
字号:
//线程调度演示
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -