Foundations of Scalable Systems by Ian Gorton

Foundations of Scalable Systems by Ian Gorton

Author:Ian Gorton [Ian Gorton]
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2022-09-25T00:00:00+00:00


class ProducerConsumer { public static void main(String[] args) BlockingQueue buffer = new LinkedBlockingQueue(); Producer p = new Producer(buffer); Consumer c = new Consumer(buffer); new Thread(p).start(); new Thread(c).start(); } } class Producer implements Runnable { private boolean active = true; private final BlockingQueue buffer; public Producer(BlockingQueue q) { buffer = q; } public void run() { try { while (active) { buffer.put(produce()); } } catch (InterruptedException ex) { // handle exception} } Object produce() { // details omitted, sets active=false } } class Consumer implements Runnable { private boolean active = true; private final BlockingQueue buffer; public Consumer(BlockingQueue q) { buffer = q; } public void run() { try { while (active) { consume(buffer.take()); } } catch (InterruptedException ex) { // handle exception } } void consume(Object x) { // details omitted, sets active=false } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.