/** * ¹¦ÄÜ£ºÀí½âÏ̵߳÷ÊÔÖÐÓÅÏȼ¶ * ²½Ö裺 * */ import java.util.*; public class ThreadPriority { public static void main(String[] args) { //ÓÃThreadÀàµÄ×ÓÀà´´½¨Ïß³Ì InheritThread rtd = new InheritThread(); rtd.setPriority(1); rtd.start(); //ÓÃRunnalbe½Ó¿ÚÀàµÄ¶ÔÏó´´½¨Ïß³Ì Runnable r = new RunnableThread(); Thread rt = new Thread(r); rt.setPriority(10); rt.start(); } } class InheritThread extends Thread { public void run() { System.out.println("InheritThread is running..."); for(int i=0; i<10; i++) { System.out.println("InheritThread:i="+i); try { Thread.sleep((int)Math.random() * 1000); } catch(InterruptedException e) { } } } } class RunnableThread implements Runnable { //×Ô¶¨ÒåÏ̵߳Ärun()·½·¨ public void run() { System.out.println("RunnableThread is running..."); for(int i=0; i<10; i++) System.out.println("RunnalbeThread: i="+i); try { Thread.sleep((int)Math.random() * 1000); } catch(InterruptedException e) { } } }