码迷,mamicode.com
首页 > 编程语言 > 详细

3.线程基本信息

时间:2016-10-04 11:42:42      阅读:189      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!