• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

LinkedBlockingDeque offerFirst  RSS feed

 
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.
 
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.
 
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
 
author
Sheriff
Posts: 23607
138
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: 23607
138
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!