zoukankan      html  css  js  c++  java
  • 线程的优先级

    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();
    
    	}
    
    }
    

      

  • 相关阅读:
    hdu6148 Valley Numer
    NOI2007 生成树计数
    bzoj3336 Uva10572 Black and White
    hdu1693 eat the trees
    【模板】插头dp
    bzoj4712 洪水
    ZJOI2010 基站选址
    poj2376 Cleaning Shifts
    bzoj4367 [IOI2014]holiday假期
    bzoj4951 [Wf2017]Money for Nothing
  • 原文地址:https://www.cnblogs.com/xyk1987/p/8259840.html
Copyright © 2011-2022 走看看