[code]
class test extends Thread 

public test (String str)
{
super(str);
}
public void run()
{
for(int i=0;i<20;i++){
System.out.println(getName());
}
}
}public class ThreadTest {
public static void main(String []args)
{
test t1=new test("Thread1");
test t2=new test("Thread2");
test t3=new test("Thread3");
t1.setPriority(2);
t2.setPriority(5);
t3.setPriority(8);
t1.start();
t2.start();
t3.start(); 
}
}[/code]
输出结果是不确定的,其中如下是一种:
Thread1
Thread2
Thread1
Thread2
Thread1
Thread1
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread2
Thread1
Thread1
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread3
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
Thread1
这是个关于线程优先级的程序,为何线程不是按照优先级由高到底的顺序执行呢?
如果将线程优先级设置为相同的,那两种情况输出结果会有什么区别?