我会
Camera
BlockingQueue
-可能因此成为
MovieCamera
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
private final BlockingQueue<Object> pictures = new ArrayBlockingQueue<>();
private final Camera camera = new Camera(pictures);
然后,您可以为队列提供数据,而不仅仅是存储图片。
public static class Camera {
private final BlockingQueue<Object> pictureQueue;
public Camera(BlockingQueue<Object> pictureQueue) {
this.pictureQueue = pictureQueue;
}
public void takePicture() {
System.out.println("Taking picture...");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
pictureQueue.put(new Object());
System.out.println("Finished taking picture.");
}
}