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
17
votes
3 answers

size of ConcurrentLinkedQueue

Reading Java's ConcurrentLinkedQueue Docs, I wonder why it is not possible for the implementation to store the size: Beware that, unlike in most collections, the size method is NOT a constant-time operation. Because of the asynchronous nature of…
hotzen
  • 2,800
  • 1
  • 28
  • 42
17
votes
9 answers

Insert into an STL queue using std::copy

I'd like to use std::copy to insert elements into a queue like this: vector v; v.push_back( 1 ); v.push_back( 2 ); queue q; copy( v.begin(), v.end(), insert_iterator< queue >( q, q.front() ) ); But this fails to compile,…
Andy Balaam
  • 6,423
  • 6
  • 34
  • 37
17
votes
3 answers

Iterate through Queue of Objects in Order

I have created a queue containing objects which I would like to iterate through in the order that they were placed within the queue (First object placed in queue, 2nd object placed in queue, 3rd object...) I saw a way of doing this online but I'm…
user2268507
17
votes
5 answers

Is there a better way to implement a Remove method for a Queue?

First of all, just grant that I do in fact want the functionality of a Queue -- FIFO, generally only need Enqueue/Dequeue, etc. -- and so I'd prefer an answer other than "What you really want is a List" (I know about RemoveAt). For example,…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
17
votes
1 answer

Thread safe queue in Java

I want to implement a queue, that is hit by multiple threads. This is stack is in a singleton class. Now, a simple solution is to synchronize this? I assume it would need this as standard? However, I want to prioritize writing to it. So, write is…
Matthew Smith
  • 366
  • 2
  • 4
  • 16
16
votes
3 answers

Best substitute, successor or alternative for ASIHTTP for a download queue

I've recently read the news on http://allseeing-i.com that ASIHTTP is being discontinued. I have much respect for the makers of the library. However, I am now looking for a substitute that also supports queued download (multithreaded) on iOS, that…
brainray
  • 12,512
  • 11
  • 67
  • 116
16
votes
3 answers

Ordinary Queue vs SEDA Queue

Being new to Apache Camel, I was recently reviewing its long list of components and stumbled upon their support for SEDA queue components. The page didn't make much sense to me, so I did a couple of online searches for the term "SEDA queue" and got…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
16
votes
3 answers

Is there a FIFO stream in Scala?

I'm looking for a FIFO stream in Scala, i.e., something that provides the functionality of immutable.Stream (a stream that can be finite and memorizes the elements that have already been read) mutable.Queue (which allows for added elements to the…
Stefan Endrullis
  • 4,150
  • 2
  • 32
  • 45
16
votes
5 answers

Android: intentservice, how abort or skip a task in the handleintent queue

i have an activity ("ApplicationActivity") that call an intent service ("DownloadService") The intentService download files from internet in background, but i want to be able to abort a specific download......... So let's say that i put 5 files in…
Sgotenks
  • 1,723
  • 4
  • 20
  • 34
16
votes
4 answers

Using many consumers in SQS Queue

I know that it is possible to consume a SQS queue using multiple threads. I would like to guarantee that each message will be consumed once. I know that it is possible to change the visibility timeout of a message, e.g., equal to my processing time.…
p.magalhaes
  • 7,595
  • 10
  • 53
  • 108
16
votes
1 answer

Why is std::queue not thread-safe?

The topic says it. I don't understand why the std::queue (or in general: any queue) is not thread-safe by its nature, when there is no iterator involved as with other datastructures. According to the common rule that at least one thread is writing…
netik
  • 1,736
  • 4
  • 22
  • 45
16
votes
5 answers

Communicating end of Queue

I'm learning to use the Queue module, and am a bit confused about how a queue consumer thread can be made to know that the queue is complete. Ideally I'd like to use get() from within the consumer thread and have it throw an exception if the queue…
intuited
  • 23,174
  • 7
  • 66
  • 88
16
votes
4 answers

Why are my Laravel Queue Jobs failing after 60 seconds?

The Situation I'm using Laravel Queues to process large numbers of media files, an individual job is expected to take minutes (lets just say up to an hour). I am using Supervisor to run my queue, and I am running 20 processes at a time. My…
slifty
  • 13,062
  • 13
  • 71
  • 109
16
votes
3 answers

How to send the password reset link via email using queue in laravel 5

I am using the ResetsPasswords trait by laravel to implement password reset. What I would like to achieve is to send the email using queue. Digging through the code I found the line below in function postEmail(): $response =…
Fokwa Best
  • 3,322
  • 6
  • 36
  • 51
16
votes
1 answer

PostgreSQL - implementing a reliable queue

I am trying to implement a reliable queue with multiple writers and a multiple readers using postgres database. How to avoid missing rows when a queue reader scans a table then in-progress transactions commit after it reads. We have a reader…
Chandra
  • 1,577
  • 3
  • 21
  • 28