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

    线程的优先级:
    1-min
    10-max
    5-normal
    优先级只是可能会优先占据资源,不会一定。

    class ThRun implements Runnable{
    	public void run() {
    		for (int i = 0; i < 5; i++) {
    			try {
    				Thread.sleep(1000);
    				System.out.println(Thread.currentThread().getName()+":"+i);
    				
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }
    public class ThreadDemo03 {
    
    	public static void main(String[] args) {
    		Thread t1=new Thread(new ThRun(),"A");
    		Thread t2=new Thread(new ThRun(),"B");
    		Thread t3=new Thread(new ThRun(),"C");
    		
    		t1.setPriority(Thread.MIN_PRIORITY);
    		t2.setPriority(Thread.NORM_PRIORITY);
    		t3.setPriority(Thread.MAX_PRIORITY);
    		
    		t1.start();
    		t2.start();
    		t3.start();
    	}
    
    }
    

     输出:

    B:0
    C:0
    A:0
    C:1
    B:1
    A:1
    A:2
    B:2
    C:2
    C:3
    B:3
    A:3
    B:4
    C:4
    A:4
    
  • 相关阅读:
    linux 第五天
    linux 第四天
    二进制 位运算
    二进制
    java 方法的调用过程
    Linux 第三天
    Linux 第二天
    Linux
    学习了半个多月的TankGame
    学习第一天(spring)
  • 原文地址:https://www.cnblogs.com/zhhy236400/p/10490627.html
Copyright © 2011-2022 走看看