zoukankan      html  css  js  c++  java
  • 3.线程基本信息

     Thread.currentThread():static  当前线程

     方法: setName()    getName()  isAlive()

     优先级概率 非绝对的优先级

    t1.setPriority(Thread.MAX_PRIORITY); t1.getPriority();

     * MAX_PRIORITY 10

     * NORM_PRIORITY 5

     * MIN_PRIORITY 1

    /**
     * 描述:优先级 概率 非绝对的优先级
     * MAX_PRIORITY 10
     * MIN_PRIORITY 1
     * NORM_PRIORITY 5
     * @author cookie
     */
    public class InfoDemo02 {
    	public static void main(String[] args) throws InterruptedException {
    		MyThread it1= new MyThread();
    		Thread p1 = new Thread(it1,"挨踢1");
    		MyThread it2= new MyThread();
    		Thread p2 = new Thread(it2,"挨踢2");
    		p1.setPriority(Thread.MAX_PRIORITY);//设置优先级
    		p2.setPriority(Thread.MIN_PRIORITY);//设置优先级
    		p1.start();
    		p2.start();
    		Thread.sleep(100);
    		it1.stop();
    		it2.stop();
    		
    	}
    }
    class MyThread implements Runnable {
    	private int num = 0;
    	private boolean flag = true;
    	@Override
    	public void run() {
    		while(flag){
    			System.out.println(Thread.currentThread().getName()+"--->"+ num++);
    		}
    	}
    	public void stop(){
    		this.flag = false;
    	}
    }
    

      

  • 相关阅读:
    install kde in ubuntu
    Upgrade to or Install Cinnamon 2.4 in Ubuntu
    enjoy dollar vs cash dollar
    opencv linux
    高频交易都有哪些著名的算法
    wpf
    opencv mat flags含义
    gphoto2 canon eos450d
    gphoto2
    task optimization之superglue分析
  • 原文地址:https://www.cnblogs.com/blogofcookie/p/5930154.html
Copyright © 2011-2022 走看看