氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          java線程數據共享1

          //在同一線程里的所有模塊使用的是同一數據,其實下面代碼就是ThreadLocal的原理,

          //用這個就可以簡單的實現,ThreadLocal的代碼實現請看 java線程數據共享2

           

          public class ThreadShareDataTest {

           private static Map shareData = new HashMap();

           public static void main(String[] args) {
            for (int i = 0; i < 2; i++) {
             new Thread() {
              public void run() {
               int data = new Random().nextInt();
               shareData.put(Thread.currentThread(), data);

               System.out.println(Thread.currentThread().getName() + data);
               System.out.println("moudle A in "
                 + Thread.currentThread().getName() + new A().get());
               System.out.println("moudle B in "
                 + Thread.currentThread().getName() + new B().get());

              }
             }.start();
            }

           }

           static class A {
            public int get() {
             return (Integer) shareData.get(Thread.currentThread());
            }
           }

           static class B {
            public int get() {
             return (Integer) shareData.get(Thread.currentThread());
            }
           }

          }

          posted on 2012-09-27 11:57 你爸是李剛 閱讀(152) 評論(0)  編輯  收藏


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


          網站導航:
           
          <2012年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 靖边县| 布尔津县| 金沙县| 衡南县| 南部县| 金门县| 勐海县| 温宿县| 长岭县| 河池市| 彭阳县| 宿松县| 突泉县| 宜阳县| 屏山县| 内乡县| 龙海市| 赤城县| 嘉定区| 盐池县| 扶沟县| 铁岭县| 牡丹江市| 西乌珠穆沁旗| 汉中市| 秭归县| 龙泉市| 昌宁县| 新余市| 小金县| 庆云县| 康保县| 余江县| 天峨县| 洛隆县| 临猗县| 富锦市| 广饶县| 沂南县| 布拖县| 凤冈县|