少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          package com.abin.lee.collection.volatiler;
          public class MyThread implements Runnable{
          private volatile boolean flag=false;
          public void run() {
          while(!flag){
          try {
          System.out.println("before");
          Thread.sleep(3000);
          System.out.println("after");
          } catch (Exception e) {
          e.printStackTrace();
          }
          flag=true;
          }
          }
          public void setDone(boolean flag){
          this.flag=flag;
          }
          }






          測試代碼:
          package com.abin.lee.collection.volatiler;
          public class MyVolatileOne {
          public static void main(String[] args) {
          MyThread myThread=new MyThread();
          Thread thread=new Thread(myThread);
          thread.start();
          }
          }
          posted on 2012-09-01 15:56 abin 閱讀(306) 評論(0)  編輯  收藏 所屬分類: JavaMultithread
          主站蜘蛛池模板: 中牟县| 申扎县| 泰顺县| 北碚区| 湖州市| 罗江县| 米脂县| 涞源县| 南平市| 大田县| 新泰市| 贵溪市| 贺兰县| 咸阳市| 张家川| 勐海县| 从江县| 济源市| 泉州市| 南汇区| 普洱| 台山市| 嫩江县| 中江县| 阿拉善右旗| 芦溪县| 察哈| 万年县| 梁平县| 新绛县| 正阳县| 石柱| 兴城市| 浠水县| 塔城市| 宁夏| 商城县| 柳州市| 上林县| 若尔盖县| 陕西省|