少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          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;
          }
          }






          測(cè)試代碼:
          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 閱讀(299) 評(píng)論(0)  編輯  收藏 所屬分類: JavaMultithread
          主站蜘蛛池模板: 宜宾市| 万宁市| 宣汉县| 丹江口市| 深圳市| 商河县| 互助| 文山县| 太湖县| 霍林郭勒市| 柳河县| 新丰县| 巫山县| 石柱| 漠河县| 株洲市| 盈江县| 英吉沙县| 许昌市| 新密市| 仪陇县| 永川市| 北海市| 政和县| 九江县| 乌兰察布市| 定襄县| 镇巴县| 大理市| 安泽县| 余庆县| 涟水县| 佛学| 若尔盖县| 读书| 蛟河市| 麻城市| 平罗县| 大名县| 泌阳县| 府谷县|