• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedBlockingQueue.take() ever timeout?

 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm interested in using LinkedBlockingQueue in a web application.
Part of the web flow, it retrieves data to be return to the client (browser) but before it does there is some computations that is done.

I want to return the data to the client without having to wait for the computation task to complete.
Since performance of the computation task is not important, I wanted to offload it to a Queue to get processed.

Wasn't sure how the LinkedBlockingQueue would behave in a web application environment.

If there is no traffic coming to the servlet, the Queue will be empty. Was curious to know if the take() method ever timeout if the Queue remains empty for a long period of time.


I was looking at the
source code and it's a bit difficult for me to follow.


Since the "consumer" code (that takes items out of the queue) will be running in a separate thread, I wasn't sure if the thread itself will die when idle and/or the take() method will timeout.

Any thoughts on this would be greatly appreciate?
 
Henry Wong
author
Marshal
Pie
Posts: 21422
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Yim wrote:I'm interested in using LinkedBlockingQueue in a web application.
Part of the web flow, it retrieves data to be return to the client (browser) but before it does there is some computations that is done.

I want to return the data to the client without having to wait for the computation task to complete.
Since performance of the computation task is not important, I wanted to offload it to a Queue to get processed.

Wasn't sure how the LinkedBlockingQueue would behave in a web application environment.

If there is no traffic coming to the servlet, the Queue will be empty. Was curious to know if the take() method ever timeout if the Queue remains empty for a long period of time.


I was looking at the
source code and it's a bit difficult for me to follow.


Since the "consumer" code (that takes items out of the queue) will be running in a separate thread, I wasn't sure if the thread itself will die when idle and/or the take() method will timeout.

Any thoughts on this would be greatly appreciate?



Won't the poll() method work here? It is just like the take method, except that one version will return if the queue is empty, and another version will wait but only for a specified amount of time.

Henry
 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the thing, I want the "consumer" part to keep waiting for something in the queue.

That's why I was interested in using take() based on the description. But I'm not sure what the behavior is when there is nothing in the queue for a long period of time (i.e. 8hours...)

I guess I'll just have to experiment with it.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Yim wrote:That's the thing, I want the "consumer" part to keep waiting for something in the queue.

That's why I was interested in using take() based on the description. But I'm not sure what the behavior is when there is nothing in the queue for a long period of time (i.e. 8hours...)

I guess I'll just have to experiment with it.


There is no time out - not even 8 hours. There are three variations on getting things from the Queue:

1) poll(): Return immediately
2) poll(time, unit): Return after timeout
3) take(): Block continuously
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic