Questions tagged [blockingqueue]

A queue data structure that that waits (suspends the current thread) for the queue to become non-empty when retrieving an element and for space to become available in the queue when storing an element.

A queue data structure that waits (suspends the current thread) for the queue to become non-empty when retrieving an element, or for space to become available in the queue when storing an element.

References

458 questions
0
votes
1 answer

Why hasn't the PriorityBlockingQueue queue to sort elements according to the priority

This my code ,the code run the end is not my excepted. I think the PriorityBlockingQueue sorted by Priority but the end is not my expected,Who can told me why. public class TestPriorityQueue { static Random r=new Random(47); public…
wanghao
  • 271
  • 1
  • 7
  • 21
0
votes
1 answer

what's the best way to limit async send speed based on response handling speed in netty 4?

I'm writing a RPC client, which uses netty4 to do the networking. The client put requests to a map, and after receiving responses the requests' callback is triggered in channel handler and the requests are removed. During benchmark test, my sending…
0
votes
1 answer

ExecutorService fairness

I have an ExecutorService like this ExecutorService executor = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(1000, true)); and i'm sending work to it with .execute(Runnable) My…
AdrianS
  • 1,980
  • 7
  • 33
  • 51
0
votes
0 answers

How to return blocking queue to the right object?

Edited hugely ;) I have a class that starts few almost identical pattern. The way I start them: public class Start{ public static void main(String [] args){ BlockingQueue Queue1; BlockingQueue Queue2; BlockingQueue
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
1 answer

How to pass BlockingQueue?

There are two classes. One, X , has it's own blockingQueue and also method returning it: public int getQueue(){ return TaskQueue; } but it seems it returns queue's reference. And I need to operate on it in other class Y where there is…
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
0 answers

How to pass queues between ExecutorsServices that are in different classes?

I have created two patterns: one which starts class X (which contains thread started with ExecutorService, name it Es), second one starts class Y (which also contains thread started with ES). Now, both of them are started inside class Z with Es.…
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
2 answers

Java BlockingQueue appears to corrupt data during transfer

I have n producer threads feeding 1 consumer thread via BlockingQueue. I am using .put and .take (the latter when .peek != null). This is working fine for at least a dozen messages, except for the invariable data corruption, apparently during…
Will
  • 79
  • 2
  • 11
0
votes
1 answer

How to add element into another queue at once?

I have a class which starts all the threads. BlockingQueue otherQueue1 = new ArrayBlockingQueue(length); BlockingQueue niceQueue = new ArrayBlockingQueue(length); service =…
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
2 answers

How to make BlockingQueue to accept multiple types?

I have class X, class Y and class Z. If X or Y perform specific conditions, they should be put into BlockingQueue. Class Z just takes them from the queue. I know that creating something like this: BlockingQueue BQueue=new…
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
1 answer

How to take data from object from BlockingQueue?

I have class for an object with all the fields and getters. Now, one thread is putting some data into it, in my case object = new MyObject(int, int, char, int) queue.put(object); and then puts it into BlockingQueue, then the second thread is…
prgst
  • 121
  • 1
  • 1
  • 11
0
votes
2 answers

Out of Memory Error when using Executors in java

I am using the Executors framework(fixed thread pool with unbounded blocking queue) to execute tasks concurrently. But when I run a load test with about 10000 tasks created, there is a huge build up of heap memory (2.1 GB) with about 3.5 million…
0
votes
1 answer

How to inform other objects(how to "close" queue) that there will be no more elements in ArrayBlockingQueue,

I have an ArrayBlockingQueue queue; and an Author object puts elements in there: public static final String END = "db8097f51282a0188e988d6bfa994430258e24ce"; [...] for (String text : texts) { queue.put(text); …
Yoda
  • 17,363
  • 67
  • 204
  • 344
0
votes
3 answers

How can I set up a high-traffic queue

I am trying to set up a concurrent queue that will enqueue data objects coming in from one thread while another thread dequeues the data objects and processes them. I have used a BlockingCollection and used the GetConsumingEnumerable() method to…
Dennis
  • 215
  • 1
  • 3
  • 14
0
votes
1 answer

Java Blocking Queue Implementation Questions

The common implementation is here, Java's built-in implementation is here. I have two questions regarding these two implementations: 1) The first implementation use synchronized key word on put() and take() methods, which means only one thread can…
Leo Li
  • 19
  • 3
0
votes
1 answer

Blocking queue+Thread+Sequence of execution of threads

I have a blocking queue which consists of my thread objects. For me the order in which these threads were formed is important. Also each thread is associated with a key. So wht I wanted to do was, if a thread for a key is running then all other…
dtyagi
  • 11
  • 3