线程的优先级

package thread;
/**
 * 线程的优先级
 * 线程的并发运行是靠线程调度统一管理。
 * 线程不会主动获取CPU时间片,也不能决定时间片长短,只能被动的被分配。
 * 通过调整线程的优先级可以最大程度的改善获取CUP时间片的几率。
 * 理论上线程优先级i越高的线程,获取CUP时间片的次数越多
 * 线程的优先级由一个int值表示,取值范围1-10,其中1为最低,10为最高优先级,5为默认
 * @author 清风已来
 *
 */

public class Thread_Priority {

	public static void main(String[] args) {
		
		Thread norm= new Thread() {
			public void run() {
				for(int i=0; i<10000;i++) {
					System.out.println("nor");
				}
			}
		};
		
		Thread max= new Thread() {
			public void run() {
				for(int i=0; i<10000;i++) {
					System.out.println("max");
				}
			}
		};
		Thread min= new Thread() {
			public void run() {
				for(int i=0; i<10000;i++) {
					System.out.println("min");
				}
			}
		};
		min.setPriority(Thread.MIN_PRIORITY);
		max.setPriority(Thread.MAX_PRIORITY);
		norm.setPriority(Thread.NORM_PRIORITY);
		min.start();
		norm.start();
		max.start();

	}

}

  

原文地址:https://www.cnblogs.com/xyk1987/p/8259840.html