- 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
- }
- }
複製代碼 |