<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之旅 廣告
                # Runnable接口改進排隊叫號 接下來通過Runnable實現一下我們之前的排隊叫號感受一下 ```java /** * @program: ThreadDemo * @description: 銀行大廳 * @author: hs96.cn@Gmail.com * @create: 2020-08-28 */ public class BankRunnable { public static void main(String[] args) { //一個runnable實例被多個線程共享 TicketWindowRunnable ticketWindow = new TicketWindowRunnable(); Thread windowThread1 = new Thread(ticketWindow, "一號窗口"); Thread windowThread2 = new Thread(ticketWindow, "二號窗口"); Thread windowThread3 = new Thread(ticketWindow, "三號窗口"); windowThread1.start(); windowThread2.start(); windowThread3.start(); } } ``` ```java /** * @program: ThreadDemo * @description: 柜臺,業務處理窗口。繼承Runnable接口 * @author: hs96.cn@Gmail.com * @create: 2020-08-28 */ public class TicketWindowRunnable implements Runnable { private int index = 1; private static final int MAX = 50; @Override public void run() { while (index <= MAX) { System.out.println(Thread.currentThread().getName() + " 的號碼是:" + (index++)); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } } ``` 可以看到 index沒有被static修飾,一個runnable實例被多個線程共享了,運行效果如下: ![](https://img.kancloud.cn/9c/97/9c97241894065b1056dec284b53322e4_1153x382.gif) 能達到我們的目的,但是這種寫法更加好,線程的邏輯全封裝到一個實例中,所以這也是Runnable存在的必要性。
                  <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>

                              哎呀哎呀视频在线观看