我的Java方面博客

          天下難事必做于易,天下大事必做于細

          常用鏈接

          統計

          最新評論

          Java線程

           1 package org.zsk.error;
           2 
           3 public class MultiThreadDemo1_1 {
           4 
           5     public MultiThreadDemo1_1() {
           6         // TODO Auto-generated constructor stub
           7         new NewThread("1");       
           8         new NewThread("2");   
           9         new NewThread("3");
          10         new NewThread("4");
          11 
          12         System.out.println("main thread begin!");
          13         for (int i=0; i<100; i++){
          14             System.out.println("  -->  ");
          15            
          16         }
          17         System.out.println("main thread end;");
          18 
          19     }
          20 
          21     /**
          22      * @param args
          23      */
          24     public static void main(String[] args) {
          25         // TODO Auto-generated method stub
          26         new MultiThreadDemo1_1();
          27     }
          28    
          29     class NewThread implements Runnable {
          30         NewThread(String threadName){
          31             name = threadName;
          32             t = new Thread(this, name);
          33             t.start();
          34             System.out.println("new thread " + name + "begin");           
          35         }
          36        
          37         public void run(){
          38             try{
          39                 for (int i=0; i<100; i++){
          40                     System.out.println(name);
          41                     Thread.sleep(30);
          42                 }                   
          43             } catch (InterruptedException e) {
          44                 System.out.println("thread "+name+"error!");
          45             }
          46                
          47             System.out.println("thread " + name + "end;");
          48         }
          49        
          50         private String name;
          51         private Thread t;
          52     }
          53 
          54 }



          posted on 2007-08-31 19:34 張樹坤 閱讀(187) 評論(0)  編輯  收藏 所屬分類: Java


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 广昌县| 迭部县| 城固县| 隆德县| 潮安县| 兰溪市| 织金县| 连城县| 巩义市| 扶风县| 五原县| 益阳市| 社旗县| 万州区| 梓潼县| 新宁县| 东乡族自治县| 鸡东县| 侯马市| 黎城县| 尉犁县| 萍乡市| 拜城县| 竹溪县| 麦盖提县| 剑河县| 怀宁县| 万源市| 张北县| 巴东县| 萨嘎县| 乌审旗| 淄博市| 巴中市| 肃宁县| 新乡市| 沐川县| 屏山县| 泾阳县| 盐源县| 乐东|