producer-consumer

How to detect alarm-based blocking RabbitMQ producer?

久未见 提交于 2019-12-06 15:56:46
I have a producer sending durable messages to a RabbitMQ exchange. If the RabbitMQ memory or disk exceeds the watermark threshold, RabbitMQ will block my producer. The documentation says that it stops reading from the socket, and also pauses heartbeats. What I would like is a way to know in my producer code that I have been blocked. Currently, even with a heartbeat enabled, everything just pauses forever. I'd like to receive some sort of exception so that I know I've been blocked and I can warn the user and/or take some other action, but I can't find any way to do this. I am using both the

Producer Consumer Program using wait() and notify() in Java

做~自己de王妃 提交于 2019-12-06 15:50:06
I am doing classic Producer-Consumer problem in Java using low level synchronization and wait() and notify(). I know there are better implementations using structures from java.util.concurrent package but my problem revolves around low level implementation: private static ArrayList<Integer> list = new ArrayList<Integer>(); static Object obj = new Object(); public static void producer() throws InterruptedException { synchronized (obj) { while (true) { if (list.size() == 10) { System.out.println("Queue full.. Waiting to Add"); obj.wait(); } else { int value = new Random().nextInt(100); if (value

Queueing Multiple Downloads, looking for a producer consumer API

久未见 提交于 2019-12-06 15:42:55
I have an application (a servlet, but that's not very important) that downloads a set of files and parse them to extract information. Up to now, I did those operations in a loop : - fetching new file on the Internet - analyzing it. A multi-threaded download-manager seems a better solution for this problem and I would like to implement it in the fastest way possible. Some of the downloads are dependant from others (so, this set is partially ordered). Mutli-threaded programming is hard and if I could find an API to do that I would be quite happy. I need to put a group of files (ordered) in a

Java example of using ExecutorService and PipedReader/PipedWriter (or PipedInputStream/PipedOutputStream) for consumer-producer

邮差的信 提交于 2019-12-06 14:58:57
问题 I'm looking for a simple producer - consumer implementation in Java and don't want to reinvent the wheel I couldn't find an example that uses both the new concurrency package and either of the Piped classes Is there an example for using both PipedInputStream and the new Java concurrency package for this? Is there a better way without using the Piped classes for such a task? 回答1: For your task it might be sufficient to just use a single thread and write to the file using a BufferedOutputStream

Java: Producer/Consumer using BlockingQueue: having the consumer thread wait() until another object is queued

元气小坏坏 提交于 2019-12-06 14:52:53
问题 I've been having some thread related problems recently with a consumer that takes points. Here is the original, which works fine except for taking up a lot of cpu constantly checking the queue. The idea is that cuePoint can be called casually and the main thread keeps going. import java.util.List; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class PointConsumer implements Runnable { public static final int MAX

Producer/Consumer - producer adds data to collection without blocking, consumer consumes data from collection in batch

纵饮孤独 提交于 2019-12-06 14:19:47
问题 I have a Producer/Consumer usecase which is a bit unusual. I have a real world use case with some producers which I want them to be able to add objects into a collection without blocking. The consumer (just one) should block until a certain amount of objects are available in the collection (eg. 500) and then consume them in bulk. While there are less than 500 it should block and wait for the collection to fill. I don't mind if the queue exceeds this value (700, 1000 etc.) for short amount of

Dynamic generation & safe usage of spsc_queues

可紊 提交于 2019-12-06 12:51:20
问题 The only boost::lockfree that I've made work is spsc_queue , and it's amazing. However, I'd like to implement it where one thread passes information back and forth with cores - 1 threads. I was thinking that each of the worker threads would have its own set of spsc_queues , in and out, which would be stored in vector s where the main thread would pass information to one outgoing queue and then move to the next queue in the vector and so on as well as cycle through the incoming queues. Can

classical producer consumer threading

一个人想着一个人 提交于 2019-12-06 11:56:41
问题 In the Classical producer consumer problem. producer sleeps when itemCount == BUFFER_SIZE amd wakes up again when it goes down. But once itemCount grows up, producer thread is put to sleep. how can it know that itemCount has gone down and it needs to wakeup ? 回答1: In pseudo-code the producer is something like: void producer_thread() { while(true) queue.push( produce() ); } so consider the queue push method (I've used pthreads here, but the same logic applies with other libraries) void

Implementing producer consumer in Java

依然范特西╮ 提交于 2019-12-06 09:59:31
This is an implementation of producer consumer pattern for a homework. What's wrong with the below implementation. I have googled for various implementations, but I am not able to understand what went wrong in mine. I have a shared queue I synchronize the producer and consumer on the same lock Implementation Shared Queue: class SharedQueue{ public static Queue<Integer> queue = new LinkedList<Integer>(); } Producer Thread : //The producer thread class Producer implements Runnable{ public void run() { synchronized (SharedQueue.queue) { if(SharedQueue.queue.size() >=5) { try { SharedQueue.queue

Non blocking and reoccurring producer/consumer notifier implementation

元气小坏坏 提交于 2019-12-06 08:26:15
Searched hard for a piece of code which does what i want and i am happy with. Reading this and this helped a lot. I have a scenario where i need a single consumer to be notified by a single producer when new data is available but would also like the consumer to be notified periodically regardless of if new data is available. It is fine if the consumer is notified more than the reoccurring period but it should not be notified less frequent. It is possible that multiple notifications for 'new data' occur while the consumer is already notified and working. (So SemaphoreSlim was not a good fit).