萬一你要做的不是一個簡單的重復作業
第二種方式是創建Thread類的子類並在子類中實現run方法
你可能會問有什麼區別
對於創建Thread子類的第三種情況
注意在實現Runnable的這後一種情況下
import java
import java
public class Both
{
public static void
main(String args[])
}
final String urlString = args[
final String message = args[
Thread thread
{
public void run()
{
try
{
URL url = new URL(urlString);
URLConnection connection = url
InputStreamReader isr = new InputStreamReaderconnection
BufferedReader reader = new BufferedReader(isr);
int count =
while (reader
{
count++;
}
System
reader
}
catch (MalformedURLException e)
{System
catch (IOException e)
{System
}
thread
Runnable runnable = new Runnable()
{
public void run()
{
while(true)
{
System
try
{
Thread
} catch (InterruptedException e) {}
}
}
}
};
Thread thread
thread
try {
System
(
System
}
catch (IOException e) {System
System
因為有多種方式來處理線程
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27685.html