package com.itbuluoge.mythread;

class SimpleThread extends Thread
{
private int priority;
public SimpleThread(int i)
{
priority=i;
}
public void run()
{
Thread.currentThread().setPriority(priority);
for(int i=0;i<10000;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println(priority);
}
}
}
public class PriorityDemo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleThread high=new SimpleThread(Thread.MAX_PRIORITY);
SimpleThread low=new SimpleThread(Thread.MIN_PRIORITY);

high.start();
low.start();
}

}

如上述代码所示,运行的两个线程,分别设置最高和最低的优先级,我们可以看看输出结果:

10
1
10
1
10
1
10
1
10
1
10
1
10
1
10
1
1
10
1
10
10
1
10
1
1


可以初步发现,优先级高的,得到的调度会更优先一些,但是也不是非常明显。