国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

App下載
首頁(yè)javasynchronizeJava Thread - 如何實(shí)現(xiàn)生產(chǎn)者消費(fèi)模式...

Java Thread - 如何實(shí)現(xiàn)生產(chǎn)者消費(fèi)模式...

我們想知道如何實(shí)現(xiàn)生產(chǎn)者消費(fèi)模式。...
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class Main {
  static int i = 0;
  static ScheduledExecutorService executor;
  static Runnable runnable;
  static ScheduledFuture<?> future;

  public static void main(String args[]) {
    executor = Executors.newScheduledThreadPool(1);
    runnable = new Runnable() {
      @Override
      public void run() {
        System.out.println("Inside runnable" + i++);
      }
    };
    future = executor.scheduleWithFixedDelay(runnable, 0, 2, TimeUnit.SECONDS);
    try {
      Thread.sleep(4000); // sleeping for 2 seconds
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    future.cancel(false);
    future = executor.scheduleWithFixedDelay(runnable, 0, 10, TimeUnit.SECONDS);
  }
}