Questions tagged [queue]

A queue is an ordered, first-in-first-out data structure. Typical implementations of queues support pushing elements to the back and popping them off the front position.

  • A queue is not limited to a fixed capacity
    • A bounded queue is a queue limited to a fixed number of items
  • A doubly linked list is a good implementation choice

Operations

  • enqueue - pushes an element to the end of the queue
  • dequeue - pops an element from the front of the queue

See Also

Resources

Queue Wikipedia Article

11098 questions
43
votes
7 answers

Job queue as SQL table with multiple consumers (PostgreSQL)

I have a typical producer-consumer problem: Multiple producer applications write job requests to a job-table on a PostgreSQL database. The job requests have a state field that starts contains QUEUED on creation. There are multiple consumer…
code_talker
  • 531
  • 1
  • 5
  • 5
43
votes
5 answers

TThreadedQueue not capable of multiple consumers?

Trying to use the TThreadedQueue (Generics.Collections) in a single producer multiple consumer scheme. (Delphi-XE). The idea is to push objects into a queue and let several worker threads draining the queue. It does not work as expected,…
LU RD
  • 34,438
  • 5
  • 88
  • 296
43
votes
2 answers

How do you pass a Queue reference to a function managed by pool.map_async()?

I want a long-running process to return its progress over a Queue (or something similar) which I will feed to a progress bar dialog. I also need the result when the process is completed. A test example here fails with a RuntimeError: Queue objects…
David
  • 1,423
  • 1
  • 12
  • 9
43
votes
2 answers

Elegantly implementing queue length indicators to ExecutorServices

Why, oh why doesn't java.util.concurrent provide a queue length indicators for its ExecutorServices? Recently I found myself doing something like this: ExecutorService queue = Executors.newSingleThreadExecutor(); AtomicInteger queueLength = new…
Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
43
votes
3 answers

Difference in LinkedList, queue vs list

What is the difference when creating these two objects Queue test = new LinkedList(); and List test2 = new LinkedList(); What are the actual differences between test and test2? Are both of them LinkedList ? Are…
Kailua Bum
  • 1,368
  • 7
  • 25
  • 40
42
votes
6 answers

Java Collections (LIFO Structure)

I am looking in the Collections framework of Java for a LIFO Structure (Stack) without any success. Basically I want a really simple stack; my perfect option would be a Deque, but I am in Java 1.5. I would like not to have to add another class to my…
David Santamaria
  • 8,671
  • 7
  • 33
  • 43
42
votes
3 answers

How to Enqueue a list of items in C#?

Using lists I use List list = new List(); list.AddRange(otherList); How to do this using a Queue?, this Collection does not have a AddRange Method. Queue q = new Queue(); q.AddRange(otherList); //does not exists
Joe Cabezas
  • 1,397
  • 3
  • 15
  • 21
41
votes
8 answers

How can I check whether a RabbitMQ message queue exists or not?

How can I check whether a message Queue already exists or not? I have 2 different applications, one creating a queue and the other reading from that queue. So if I run the Client which reads from the queue first, than it crashes. So to avoid that i…
Jigar Sheth
  • 586
  • 2
  • 5
  • 21
39
votes
2 answers

Java BlockingQueue take() vs poll()

When consuming values from a Queue in an infinite loop -- what would be more efficient: Blocking on the Queue until a value is available via take() while (value = queue.take()) { doSomething(value); } Sleeping for n milliseconds and checking if…
isapir
  • 21,295
  • 13
  • 115
  • 116
39
votes
8 answers

java BlockingQueue does not have a blocking peek?

I have a blocking queue of objects. I want to write a thread that blocks till there is a object on the queue. Similar to the functionality provided by BlockingQueue.take(). However, since I do not know if I will be able to process the object…
rouble
  • 16,364
  • 16
  • 107
  • 102
38
votes
7 answers

How to get all pending jobs in laravel queue on redis?

The queue:listen was not run on a server, so some jobs were pushed (using Redis driver) but never run. How could I count (or get all) these jobs? I did not find any artisan command to get this information.
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
38
votes
7 answers

Why Java provides two methods to remove element from Queue?

The Queue implementation in Java has two methods to remove element, One is remove() which throws exception and other one is poll() which returns null for an empty queue. I have two doubts: Why Queue has different implementation to remove…
munish
  • 389
  • 1
  • 3
  • 3
38
votes
4 answers

python multiprocessing - process hangs on join for large queue

I'm running python 2.7.3 and I noticed the following strange behavior. Consider this minimal example: from multiprocessing import Process, Queue def foo(qin, qout): while True: bar = qin.get() if bar is None: break …
user545424
  • 15,713
  • 11
  • 56
  • 70
36
votes
3 answers

How to put items into priority queues?

In the Python docs, The lowest valued entries are retrieved first (the lowest valued entry is the one returned by sorted(list(entries))[0]). A typical pattern for entries is a tuple in the form: (priority_number, data). It appears the queue will…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
36
votes
7 answers

Concurrent Set Queue

Maybe this is a silly question, but I cannot seem to find an obvious answer. I need a concurrent FIFO queue that contains only unique values. Attempting to add a value that already exists in the queue simply ignores that value. Which, if not for the…
Steve Skrla
  • 1,620
  • 5
  • 16
  • 24