?? multithread.java
字號:
/**
* <p>Title: 創建多線程</p>
* <p>Description: 使用構造器,創建多線程。</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: multiThread.java</p>
* @author 杜江
* @version 1.0
*/
public class multiThread
{
/**
*<br>方法說明:主方法
*<br>輸入參數:
*<br>返回類型:
*/
public static void main (String [] args){
new multiThread();
}
/**
*<br>方法說明:構造器。構造多個線程,并啟動它們。
*<br>輸入參數:
*<br>返回類型:
*/
multiThread(){
for (int i = 0; i < 5; i++){
System.out.println("Creating thread "+i);
innThread mt = new innThread (i);
mt.start ();
}
}
/**
*<br>類說明:內部類通過繼承Thread實現線程
*<br>類描述:通過構造器參數,區別不同的線程
*/
class innThread extends Thread
{
int count;
innThread(int i){
count=i;
}
/**
*<br>方法說明:內部類線程主體,繼承Thread必須實現的方法。
*<br>輸入參數:
*<br>返回類型:
*/
public void run ()
{
System.out.println("now "+count+" thread is beginning..... ");
try{
sleep(10-count);
}catch(Exception e){
System.out.println(e);
}
System.out.println("\n"+count+" thread is end!");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -