JAVA学习day99--线程的优先级

package day10;
/**
 * 
 * 线程优先级
 * 线程对线程调度的工作是不可控的 ,即:
 * 线程只能被动被分配CPU时间,而不能主动获取到
 * 
 * 线程调度会尽可能的将CPU时间分配的几率做到均匀,但是多个
 * 线程并发运行,并不保证一个线程一次这样交替运行
 * 
 * 可以通过调整线程的优先级来分配CPU时间片几率
 * 理论上线程优先级越高的线程,获取CPU时间片的次数越多
 * 
 * 线程的优先级有10级,分别 用整数1-10表示
 * 其中1最低 5默认 10最高
 * @author soft01
 *
 */
public class Threadd_setPriority {

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

	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值