<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                > ### `ThreadLocal` * `ThreadLocal`,即線程變量。在`ThreadLocal`類中有一個`static`聲明的`Map<ThreadID,Object>`,用于存儲每一個線程的變量副本構,`key`為線程`id`,`value`為自己定義的任意數據類型并綁定到對應的`key`的線程上。 * 示例代碼 ``` public class ThreadLocalDemo { //類型為map的ThreadLocal public static final ThreadLocal<HashMap<Integer, Long>> TIME_THREADLOCAL = new ThreadLocal<HashMap<Integer, Long>>() { //重寫initialValue方法,初始化 protected HashMap<Integer, Long> initialValue() { return new HashMap<Integer, Long>(); } }; // TIME_THREADLOCAL 針對每個線程 創建了一個副本 public static class ThreadDemo implements Runnable{ int index; public ThreadDemo(int index){ this.index = index; } public static final void begin() { HashMap<Integer, Long> map = new HashMap<Integer, Long>(); map.put(0, System.currentTimeMillis()); //set TIME_THREADLOCAL.set(map); } public static final long end() { //get return System.currentTimeMillis() - TIME_THREADLOCAL.get().get(0); } public void run(){ ThreadDemo.begin(); try { TimeUnit.SECONDS.sleep(this.index); // TimeUnit.SECONDS.sleep((int)(Math.random()*10)); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Thread: " + Thread.currentThread().getName() + " | Cost: " + ThreadDemo.end() + " mills"); } } public static void main(String[] args) throws Exception { for (int i = 0; i < 10; i++) { Thread thread = new Thread(new ThreadDemo(i), String.valueOf(i)); thread.start(); } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看