File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedBlockingDeque offerFirst

 
Gary Blomquist
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible for offerFirst(E e) of LinkedBlockingDeque to block? The javadoc says:

"Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available."

The verbiage "if it is possible to do so immediately" seems to indicate that it can NOT block but I have a Thread that is calling this method that either dies or blocks indefinitely. The run loop is inside a try/catch block so the thread should not die. I am wondering if the thread might be seizing up on the call to offerFirst.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into source code:
http://www.docjar.com/html/api/java/util/concurrent/LinkedBlockingDeque.java.html

This is an implementation of offerFirst:


This is a declaration of 'lock' variable:


It seems that offerFirst blocks.
 
Adam Smolnik
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.

Thread that is calling this method that either dies or blocks indefinitely.


It is rather a strange situation. It could have been locked only during some longer traversal, for example:



Could you show more your LinkedBlockingDeque's client code?

Adam
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ireneusz Kordal wrote:
It seems that offerFirst blocks.


When the JavaDoc implies that it doesn't block, it is saying that there is no situation that can cause it to block indefinitely -- which is generally caused by a call to the condition variable await() method, because the queue is full.

The locks are just held long enough to do the task, and maintain thread safety.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Smolnik wrote:
It is rather a strange situation.

Could show more your LinkedBlockingDeque's client code?


Agreed. We need to see the client code -- as it is likely something else, and not being blocked while calling the offerFirst() method.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic