少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            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 閱讀(303) 評論(0)  編輯  收藏 所屬分類: JavaMultithread
          主站蜘蛛池模板: 三都| 定陶县| 浦东新区| 金溪县| 台湾省| 来宾市| 偏关县| 德保县| 大埔区| 商都县| 甘肃省| 阳城县| 祁门县| 建始县| 德格县| 忻城县| 新乡县| 长汀县| 将乐县| 扶余县| 石狮市| 呼和浩特市| 夏邑县| 武义县| 安庆市| 察雅县| 双牌县| 福建省| 获嘉县| 青海省| 南宫市| 班戈县| 吉林市| 贞丰县| 扎兰屯市| 新乡县| 德江县| 偏关县| 新干县| 永福县| 儋州市|