java 多线程的优先级

 1 class MyThread implements Runnable{
2 public void run(){
3 for(int i=0;i<5;i++){
4 try {
5 Thread.sleep(500);
6 } catch (Exception e){
7 }
8 System.out.println(Thread.currentThread().getName()+"运行,i="+i);
9 }
10 }
11 }
12 public class ThreadDemo {
13 public static void main(String[] args) {
14 Thread t1=new Thread(new MyThread(),"线程A");
15 Thread t2=new Thread(new MyThread(),"线程B");
16 Thread t3=new Thread(new MyThread(),"线程C");
17 t1.setPriority(Thread.MIN_PRIORITY);
18 t2.setPriority(Thread.MAX_PRIORITY);
19 t3.setPriority(Thread.NORM_PRIORITY);
20 t1.start();
21 t2.start();
22 t3.start();
23
24 }
25 }
26

线程的优先级越高不一定会先执行,而由其CPU的调度决定。。。

posted @ 2012-03-12 20:53  谈笑风生膜法师  阅读(271)  评论(0编辑  收藏  举报