魚躍于淵

          First know how, Second know why !
          posts - 0, comments - 1, trackbacks - 0, articles - 49

          Thread method synchronized

          Posted on 2008-12-06 12:14 魚躍于淵 閱讀(128) 評論(0)  編輯  收藏 所屬分類: j2se
           1 
           2 public class TT implements Runnable{
           3     int b = 10 ;
           4     
           5     public synchronized void m1() throws Exception{
           6         b = 1000 ;
           7         Thread.sleep(5000);
           8         System.out.println("m1 : b = " + b) ;
           9     }
          10     
          11     public void m2(){
          12         System.out.println("m2 : b = " + b) ;
          13     }
          14     
          15     public void run(){
          16         try{
          17             m1() ;
          18         }catch(Exception ex){
          19             ex.printStackTrace() ;
          20         }
          21     }
          22     
          23     public static void main(String[] args) throws Exception{
          24         TT tt = new TT() ;
          25         Thread t = new Thread(tt) ;
          26         t.start() ;
          27         Thread.sleep(2000) ;
          28          tt.m2() ;
          29     }
          30 }
          主站蜘蛛池模板: 贵州省| 彭州市| 略阳县| 谢通门县| 昆山市| 灵丘县| 平山县| 稻城县| 密山市| 鹿邑县| 琼海市| 博乐市| 阜南县| 长葛市| 双柏县| 托里县| 华阴市| 类乌齐县| 米泉市| 温宿县| 平定县| 静宁县| 拜泉县| 区。| 蒙自县| 曲阜市| 靖安县| 嘉荫县| 黄平县| 庄河市| 营山县| 金坛市| 旬邑县| 吉林市| 边坝县| 兴城市| 连江县| 华容县| 宽甸| 辽宁省| 岳西县|