Questions tagged [producer-consumer]

The Producer-Consumer Problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.

The Producer-Consumer Problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer.

The solution for the producer is to either go to sleep or discard data if the buffer is full. The next time the consumer removes an item from the buffer, it notifies the producer who starts to fill the buffer again. In the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means of inter-process communication, typically using semaphores. An inadequate solution could result in a deadlock where both processes are waiting to be awakened. The problem can also be generalized to have multiple producers and consumers.

References

1564 questions
0
votes
1 answer

Variation of a Single Producer Single Consumer problem

I have a situation like this: One single Producer executes many DB queries - the results are sent as messages and arrive to the queue of the single consumer (messages arrive with no special order ) On the other side - a single consumer reads these…
RRR
  • 1
0
votes
1 answer

how to find out the produce order acked in the librdkafka library?

in librdkafka, The data has been put in the transmission queue via following function. virtual ErrorCode produce (Topic *topic, int32_t partition, int msgflags, void *payload, size_t len, const void *key, size_t key_len, void *msg_opaque) The…
0
votes
1 answer

Apache Camel ProducerTemplate

Hi I am using apache camel + Spring and defined a configure like public class MyOrderConsumerRouterBuilder extends RouteBuilder implements InitializingBean, ApplicationContextAware{ @Override public void configure() throws Exception { …
Vijay Kumar Rajput
  • 1,071
  • 1
  • 10
  • 30
0
votes
2 answers

Exercise on synchronization and threads

I'm doing a simple exercise to understand the concept of threads and synchronization. But I don't know whether the code is correct or not. public class PopcornMachine { // shared resource private boolean isBinFull = false; // producer…
ahrooran
  • 931
  • 1
  • 10
  • 25
0
votes
1 answer

A producer-consumer code using semaphore compiling but not running

i am in a very sticky situation as i am unable to figure out the problem with my producer-consumer problem using pthreads. the code compiles but when i run the code nothing happens and the expected output does not show. i believe there is a probelem…
0
votes
1 answer

Proper implementation of producer-consumer scenario and "graceful" termination of thread pool

I am working on my first multi-threaded project and thus have a couple of things that I am unsure of. Details on my setup was on a previous question, in short: I have a thread pool implemented by Executors.newFixedThreadPool(N). One thread is given…
posdef
  • 6,498
  • 11
  • 46
  • 94
0
votes
1 answer

javafx, hw do I get valus from main process

This is basicly a simple producer - consumer application. The code example is the following: public class MyMainClass extends Application { // blocking queue that will be shared among my prcesses BlockingQueue bq; public static void…
bog
  • 1,323
  • 5
  • 22
  • 34
0
votes
1 answer

Consumer - Producer problem with named pipes in C

I have challenge to implement two task using named pipes in C: Multiple producer - single consumer Single producer - multiple consumer I already did single producer - single consumer problem but I'm not sure how can I start solving above tasks,…
Kamil W
  • 2,230
  • 2
  • 21
  • 43
0
votes
2 answers

Consuming an operation with no body using camel-cxf-endpoint

I have a source web service which has an operation which does not take any body as a request. This is the request it expects: I…
julien carax
  • 323
  • 6
  • 22
0
votes
1 answer

How to set Kafka consumer configuration to consume messages from now?

I am new to Kakfa and learning on to produce and consume messages to and from a Kafka Topic. I am using the Kafka configuration using @EnableKafka @EnableKafka @Configuration public class ConsumerConfig implements ApplicationContextAware { …
KayV
  • 12,987
  • 11
  • 98
  • 148
0
votes
2 answers

Concurrent Programming in Java. Trying to simulate a set of checkout counters

I'm trying to use Java to simulate a set of Checkout counters in a shopping center. This is the assumption. There are 5 checkout counters. Like a real shopping center there is a line at each counter. Each counter services one customer at a time. I…
0
votes
2 answers

Is it possible for exceptions to be caught asynchronously without awaiting a task?

I have a low level CAN device class that I would like to create an onMessageReceive event for. I have several high level device classes that could use an instance of this CAN class. I would like to attach the high level device class' message parser…
0
votes
2 answers

Kafka consumer threads with same group id consuming same record

I need to consume records from Kafka partition in multiple Thread with unique records on each thread to process. I have following code, I don't know what was the mistake public class ConsumerThread implements Runnable { public String name; …
0
votes
2 answers

Kafka producer poor performance

I have an issue with kafka producer. Actually I am using spring kafka, and sending messages through KafkaTemplate leke this: DefaultKafkaProducerFactory defaultKafkaProducerFactory = new…
0
votes
1 answer

Java Multiple Producer and Multiple with single queue in Java?

I have three Producers P1,P2,P3 and Three consumers with single shared queue. Producer P1 will put/insert X1,X2,X3 into queue and it should be consumed only by Consumer C1 not other Consumers(C2,C3). Basically Consumers C1 should only consume values…