读书人

线程优先级无效有关问题

发布时间: 2012-08-15 16:57:17 作者: rapoo

线程优先级无效问题。
有如下代码,设置了 两个线程T1,T2 ,T2设置了优先,但是感觉没有作用,最后还是 T1先跑完。这是为什么?

Java code
public class TestPriority{    public static void main(String[] args)    {          Thread t1 = new Thread(new T1());          Thread t2 = new Thread(new T2());          t2.setPriority(Thread.NORM_PRIORITY+3);          t1.start();          t2.start();              }}class T1 implements Runnable{      public void run()      {            for(int i=1;i<=10000;i++)            {                 System.out.println("T1:"+i);            }      }}class T2 implements Runnable{      public void run()      {            for(int i=0;i<10000;i++)            {                  System.out.println("-------------T2:"+i);            }      }}


[解决办法]
http://topic.csdn.net/u/20120606/11/23451fc6-cc64-4e7f-a6d0-640733c5e59a.html
这里有你的答案

读书人网 >J2SE开发

热点推荐