標題:
ThreadTest
[打印本頁]
作者:
ray
時間:
2012-11-2 21:15
標題:
ThreadTest
class MyThread extends Thread
{
int myID;
MyThread(int id)
{
this.myID = id;
}
public void run()
{
for(int i = 0 ; i < 10;i++)
{
System.out.println("Thread<"+myID+">執行了第"+i+"次!");
try
{
Thread.sleep(1000);
}
catch(Exception e)
{}
}
}
}
public class ThreadTest
{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
複製代碼
作者:
ray
時間:
2012-11-2 21:22
public static void main(String[] args)
{
// TODO Auto-generated method stub
Thread t1 = new MyThread(1);
Thread t2 = new MyThread(2);
t1.start();
t2.start();
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2