1銆侀氳繃瀹炵幇Runnable鎺ュ彛瀹氫箟涓涓敱Thread椹卞姩鐨勪換鍔★紝鍚庨氳繃鎶婅嚜宸變紶緇橳hread鐨勬瀯閫犳潵鍚姩涓涓嚎紼?Runnable娌℃湁榪斿洖鍊?濡傞渶榪斿洖鍊煎垯浣跨敤Callable鎺ュ彛)銆?br />@瀹炵幇Runnable鐨勪竴涓換鍔?br />
public class CountDown implements Runnable {
protected int count = 10;
public static int taskCount = 1;
public final int id = taskCount ++;
@Override
public void run() {
// TODO Auto-generated method stub
while(count -- >0)
{
System.out.println(""+count);
}
System.out.println("count over");
Thread.yield();
}
}
@閫氳繃鎶婁換鍔′紶緇橳hread鐨勬瀯閫犳潵鍚姩綰跨▼
public class MainThread {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t = new Thread(new CountDown());
t.start();
}
}
2銆佺洿鎺ョ戶鎵胯嚜Thread鏉ュ垱寤虹嚎紼?br />@緇ф壙鑷猅hread鐨勭嚎紼?br />
public class CountDown3 extends Thread {
private static int step = 0;
private final int id = step++;
private int count = 10;
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while(count-- > 0)
{
System.out.println(count);
Thread.yield();
}
}
}
@鍚姩姝ょ嚎紼?br />public class MainThread {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t = new CountDown3();
t.run();
}
}

]]>