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

      

  • 相关阅读:
    做数据库维修工、还是码农,讨论走下神坛的职业【摘自vage】
    4.4 Web存储
    4.3 createjs
    4.2 HTML Canvas标签
    4.2 拖放
    4.1 HTML5 音频
    3.2 JacaScript面向对象
    3.1 JavaScript基础
    2.7 CSS动画
    2.6 CSS基本操作
  • 原文地址:https://www.cnblogs.com/blogofcookie/p/5930154.html
Copyright © 2011-2022 走看看