氟塑料離心泵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)  編輯  收藏


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


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

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業(yè)網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 潮安县| 如皋市| 贵德县| 教育| 台山市| 文化| 璧山县| 化隆| 合肥市| 台江县| 合江县| 武强县| 固阳县| 定南县| 金溪县| 郑州市| 南康市| 东光县| 清苑县| 延庆县| 两当县| 云龙县| 上饶市| 车致| 凤山县| 瑞安市| 新沂市| 财经| 吉水县| 波密县| 开封市| 腾冲县| 高邑县| 海伦市| 南澳县| 屏东县| 秭归县| 四川省| 仁化县| 长丰县| 徐州市|