My understanding of a Producer-Consumer pattern is that it could be implemented using a queue shared between the producer and the consumer. Producer submits work to a shared queue, consumer retrieves it and processes it. It could also be implemented by the producer directly submitting to the consumer (Producer threads submitting to Consumer's executor service directly).
Now, I've been looking at the Executors class that provides some common implementations of thread pools. The method newFixedThreadPool, according to the spec, "reuses a fixed number of threads operating off a shared unbounded queue". Which queue are they talking about here?
If the Producer directly submits a task to a consumer, is it the internal queue of the ExecutorService that contains the list of Runnables?
Or is it the intermediate queue, in case the producer submits to a shared queue?
May be I'm missing the whole point, but would someone please clarify?
ExecutorService
is just an interface. You could implementExecutorService
with a class that just runs each runnable as soon as it is submitted, in the same thread (and I believe there is an implementation in thejava.util.concurrent
package that does just that). But in practice, most ExecutorService implementations are a full producer-consumer implementation. – Mauramauralia