Hello,
I need a sorted stack. I mean, the element removed from the stack must be the one with great priority. Stack dimension varies a lot (becomes bigger very fast).
I need also to search elements in that stack.
Does Java give some good implementation for this? What class or algorithm do you suggest for this?
I'm using a PriorityQue...
Hello,
I am looking for a method to implement lock-free queue data structure that supports single producer, and multiple consumers. I have looked at the classic method by Maged Michael and Michael Scott (1996) but their version uses linked lists. I would like an implementation that makes use of bounded circular buffer. Something that us...
public class PriorityQueue<T> {
private PriorityNode<T> head, tail;
private int numItems;
public PriorityQueue(){
numItems = 0;
head=null;
tail=null;
}
public void add(int priority, T value){
PriorityNode<T> newNode = new PriorityNode<T>(priority,value);
if(numItems == 0){
head = newNode;
tail = n...
Take the PriorityQueue for example http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html#offer(E)
Can anyone give me an example of a queue where the add and offer methods are different?
According to the Collection API entry
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collection.html the add method will often seek t...
I have lockless queues written in C in form of a linked list that contains requests from several threads posted to and handled in a single thread. After a few hours of stress I end up having the last request's next pointer pointing to itself, which creates an endless loop and locks up the handling thread.
The application runs (and fails...
Possible Duplicate:
Is there a production ready lock-free queue or hash implementation in C++
I am looking for a well-tested, publicly available C/C++ implementation of a lock free queue.
I need at least multiple-producers/single-consumer functionality. Multiple-consumers is even better, if exists.
I'm targetting VC's _Inter...
How do I setup/register a callback function, in C++, to call a function when there is data to be read from a queue?
Edit 1:
Using Neil's answer for a complete answer (in header file):
#include <vector.h>
class QueueListener {
public:
virtual void DataReady(class MyQueue *q) = 0;
virtual ~QueueListener() {}
};
class...
I am new to multithreading and have designed a program that receives data from two microcontroller measuring various temperatures (Ambient and Water) and draws the data to the screen. Right now the program is singly threaded and its performance SUCKS A BIG ONE.
I get basic design approaches with multithreading but not well enough to ...
I have a script that colors the requested country on a world map with GD and PHP. The PHP requests are called with checkboxes. It kind of looks like if you call the PHP scripts too fast then it returns an "Xed out" error image. Is there a way to queue the PHP requests with setTimeout or something else, so a new checking event never fa...
I've had the following code in my application for some years and have never seen an issue from it.
while ((PendingOrders.Count > 0) || (WaitHandle.WaitAny(CommandEventArr) != 1))
{
lock (PendingOrders)
{
if (PendingOrders.Count > 0)
{
fbo = PendingOrders.Dequeue();
}
else
{
...
I have a very complex system (100+ threads) which need to send email without blocking. My solution to the problem was to implement a class called EmailQueueSender which is started at the beginning of execution and has a ScheduledExecutorService which looks at an internal queue every 500ms and if size()>0 it empties it.
While this is goi...
I am looking at open source queuing platforms that allow me do the following:
I have multiple producers, multiple consumers putting data into a queue in a multithreaded environment with the specific use case:
I want the ability for consumers to be able do the following
Peek at a message from the queue(which should mark as the message ...
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 these queues, determining the current number of elements requires a traversal of the elem...
I have implemented the standard single consumer, single producer queue as a circular buffer in C consisting of an array and two indexes: one for read, one for write.
My circular buffer is of the type that returns an error if you attempt to insert an item into a full queue and uses one empty slot to distinguish between an empty ring buff...
This might not be possible but before I rewrite part of my application I wanted to ask...
I have a JavaScript app which creates a submit <input> and observes that input's click event using Prototype's Element#observe function. For a few particular pages on one particular site which uses this app, I need to apply some additional busines...
First of all, this is my code (just started learning java):
Queue<String> qe = new LinkedList<String>();
qe.add("b");
qe.add("a");
qe.add("c");
qe.add("d");
qe.add("e");
My question:
Is it possible to add element to the queue with two values, like:
qe.add("a","1"); // where 1 is integer
So, that I know element "a" have value 1. ...
I am getting a segmentation fault with the following code after adding structs to my queue.
The segmentation fault occurs when the MAX_QUEUE is set high but when I set it low (100 or 200), the error doesn't occur. It has been a while since I last programmed in C, so any help is appreciated.
#include <stdio.h>
#include <stdlib.h>
#incl...
I have an application built that hits a third party company's web service in order to create an email account after a customer clicks a button. However, sometimes the web service takes longer than 1 minute to respond, which is way to long for my customers to be sitting there waiting for a response.
I need to devise a way to set up some...
This is my code:
Iterator it = queue.iterator();
while(it.hasNext()){
random = randNumber(1,2);
if(random == 1){
queue.poll();
} else {
queue.add("new");
queue.poll();
}
}
It gives me:
Exception in thread "test" java.util.ConcurrentModificationException
at java.util....
I want to guarantee that a task is not in a task queue more then once, so I generate a unique name based on it's payload. But, that task name is reserved for up to 7 days, which is not what I want; I only want it reserved for the duration the task is queued; it could be immediately re-queued.
Once a Task with name N is written,
any...