Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

LinkedBlockingDeque offerFirst

 
Gary Blomquist
Greenhorn
Posts: 14
  • 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
  • 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
  • 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
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!