• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Queue in Java

 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a little program to test Queue but i can't figure how put this in to class

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Hong hong",
Did you check your Private Messages ?
 
Nattakan Lukkanapinit
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:"Hong hong",
Did you check your Private Messages ?

changed
 
Istvan Kovacs
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the loop, head is always the same value, you never set it to the next element.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sidharth Dash
Greenhorn
Posts: 11
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic