aspose file tools*
The moose likes Java in General and the fly likes Queue in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Queue in Java" Watch "Queue in Java" New topic
Author

Queue in Java

Nattakan Lukkanapinit
Greenhorn

Joined: Apr 24, 2010
Posts: 16
I get the concept [FILO] of stack but a little confused about Queue [ FIFO].

Anyone have a good example that use add(), remove() [ not collections or generics].

thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What's the specific issue? I mean, the acronym kind of summarizes it pretty neatly, and it's easily differentiable from a LIFO.
Nattakan Lukkanapinit
Greenhorn

Joined: Apr 24, 2010
Posts: 16
I found a little program to test Queue but i can't figure how put this in to class

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

"Hong hong",
Did you check your Private Messages ?


[My Blog]
All roads lead to JavaRanch
Nattakan Lukkanapinit
Greenhorn

Joined: Apr 24, 2010
Posts: 16
Christophe Verré wrote:"Hong hong",
Did you check your Private Messages ?

changed
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
Nattakan Lukkanapinit wrote:I get the concept [FILO] of stack but a little confused about Queue [ FIFO].
Anyone have a good example that use add(), remove() [ not collections or generics].


Note that add and remove are Collection methods, not Queue methods.

You could read the Javadoc for BlockingQueue (it's a special kind of queue, but the code demonstrates the principle). Queues are often used to pass work from any number of clients to one or more workers. Clients put tasks/data to process on the queue, workers, running in another thread, take and process them.
If you check the Javadocs of the Queue interface, you'll see that most implementations are concurrency-related (they have 'Blocking' or 'Concurrent' in their names), plus there are some special queues (Priority(Blocking)Queue, DelayQueue).

I don't think I've ever used a queue in a single-threaded program, but you could to it.

Nattakan Lukkanapinit
Greenhorn

Joined: Apr 24, 2010
Posts: 16
This is stack and i would like to modify it to queue
I tried to put head and tail to it.
Do i have to change when add data in or pull data out ?




This is my new add for queue

Is it ok ?
I can't find the way to pull data out by tail to head
Nattakan Lukkanapinit
Greenhorn

Joined: Apr 24, 2010
Posts: 16
I already finished add and remove but now i stuck at "print all the queue".
The problem is in queue class.
this is my print queue.
It print only the head of the queue, i dont know why.



this is my code




Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
In the loop, head is always the same value, you never set it to the next element.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

Istvan Kovacs wrote:I don't think I've ever used a queue in a single-threaded program, but you could to it.


We (sort of) do. We have dozens of applications that create jobs (documents to process). We have a single threaded job that does the processing. All the job creators write to a queue (we use MQSeries), dumping in everything as fast as they can.

The single-threaded application then reads them off one at a time to process them.

It's not EXACTLY what you meant, since we have many, many single threaded apps doing this, but the need is there.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sidharth Dash
Greenhorn

Joined: May 15, 2014
Posts: 11

How dose Queue performs when when data are reguralry added and removed from it?
her i am talking about large volume of datt tipically 8 GB (40 million.) .
any answers or response will be great.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
Sidharth Dash wrote:any answers or response will be great.

Any answers should go in this thread where the OP has asked the same question.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Queue in Java