<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Thread中一些簡單的API ```java /** * @program: ThreadDemo * @description: Thread中一些簡單的API * @author: hs96.cn@Gmail.com * @create: 2020-08-28 */ public class ThreadSimpleAPI { public static void main(String[] args) { Thread t1 = new Thread(() -> { Optional.of("Hello").ifPresent(System.out::println); try { Thread.sleep(1_000); } catch (InterruptedException e) { e.printStackTrace(); } }, "t1"); t1.start(); // 線程名稱。 Optional.of(t1.getName()).ifPresent(System.out::println); // 線程ID。++threadSeqNumber Optional.of(t1.getId()).ifPresent(System.out::println); // 線程優先級,默認為5. Optional.of(t1.getPriority()).ifPresent(System.out::println); } } ``` 很簡單的api運行效果如下: ![](https://img.kancloud.cn/6e/29/6e294b1f5aa9662d98e10cf02410bc4e_960x638.gif) 接下來再通過代碼來驗證:*線程不一定會按照指定的優先級執行*。 ```java import java.util.Optional; /** * @program: ThreadDemo * @description: 線程優先級:驗證:線程不一定會按照指定的優先級執行。 * @author: hs96.cn@Gmail.com * @create: 2020-08-28 */ public class ThreadSimpleAPI2 { public static void main(String[] args) { Thread t1 = new Thread(() -> { for (int i = 0; i < 1000; i++) { Optional.of(Thread.currentThread().getName() + "-Index-" + i).ifPresent(System.out::println); } }, "t1"); t1.setPriority(Thread.MAX_PRIORITY); Thread t2 = new Thread(() -> { for (int i = 0; i < 1000; i++) { Optional.of(Thread.currentThread().getName() + "-Index-" + i).ifPresent(System.out::println); } }, "t2"); t2.setPriority(Thread.NORM_PRIORITY); Thread t3 = new Thread(() -> { for (int i = 0; i < 1000; i++) { Optional.of(Thread.currentThread().getName() + "-Index-" + i).ifPresent(System.out::println); } }, "t3"); t3.setPriority(Thread.MIN_PRIORITY); t1.start(); t2.start(); t3.start(); } } ``` 運行結果如下: ![](https://img.kancloud.cn/93/1a/931a2ae92d7bb4e239b0a3b1c6e418bb_575x387.png) 可以看到他們是交替執行的,所以線程的優先級我們應該在邏輯上去實現。這里就做個了解。
                  <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>

                              哎呀哎呀视频在线观看