試試看
用一個例子我們可以看到這是如何工作的
import java
public java TryThread extends thread
{
private string firstName; //store for first name
private string secondName; //store for second name
private long awhile //Delay in milliseconds
public TryThread(string firsName
{
this
this
awhile=delay //store the delay
setDaemon(true) //Thread is daemon
}
public static void main (string[]args)
{
//create three threads
Thread first =new TryThread(
Thread second=new TryThread(
Thread third =new TryThread(
system
first
second
thrid
try
{
system
system
}
catch (IOException e) //Hand Io exception
{
system
}
system
return;
//Method where thread execption will stare
public void run()
{
try
{
while(ture) //Loop indefinitely
{
system
sleep(awhile); //wait awhile mses
system
}
}
catch(InteruptedException e) //Hand thread interruption
{
system
}
}
}
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27755.html