首页 > 编程语言 > 详细

3.线程基本信息

时间:2016-10-04 11:42:07      阅读:170      评论:0      收藏:0      [点我收藏+]

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

  

3.线程基本信息

原文:http://www.cnblogs.com/blogofcookie/p/5930154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!