?? invokerun.java
字號:
/**
* Description:
* <br/>Copyright (C), 2008-2010, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class InvokeRun extends Thread
{
private int i ;
//重寫run方法,run方法的方法體就是線程執行體
public void run()
{
for ( ; i < 100 ; i++ )
{
//直接調用run方法時,Thread的this.getName返回的是該對象名字,
//而不是當前線程的名字。
//使用Thread.currentThread().getName()總是獲取當前線程名字
System.out.println(Thread.currentThread().getName() + " " + i);
}
}
public static void main(String[] args)
{
for (int i = 0; i < 100; i++)
{
//調用Thread的currentThread方法獲取當前線程
System.out.println(Thread.currentThread().getName() + " " + i);
if (i == 20)
{
//直接調用線程對象的run方法,
//系統會把線程對象當成普通對象,run方法當成普通方法,
//所以下面兩行代碼并不會啟動2條線程,而是依次執行2個run方法
new InvokeRun().run();
new InvokeRun().run();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -