• 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

Using of a Condition  RSS feed

 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
Preparing for the OCPJP7 I have come across the java.util.concurrent.locks.Condition.
How is it possible managing more condition with the same lock? Underneath does not it use the intrinsic lock?
Thanks in advance.





 
author
Sheriff
Posts: 23603
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nick Widelec wrote:Hi everybody,
Preparing for the OCPJP7 I have come across the java.util.concurrent.locks.Condition.
How is it possible managing more condition with the same lock? Underneath does not it use the intrinsic lock?
Thanks in advance.



Yes, it is possible to have more than one Condition variable with the same lock. However, I am not sure of your question -- why should this not be possible?

Henry
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:

Nick Widelec wrote:Hi everybody,
Preparing for the OCPJP7 I have come across the java.util.concurrent.locks.Condition.
How is it possible managing more condition with the same lock? Underneath does not it use the intrinsic lock?
Thanks in advance.



Yes, it is possible to have more than one Condition variable with the same lock. However, I am not sure of your question -- why should this not be possible?

Henry



Hi Henry,
I am not saying that it is impossible, or why it is possible or anything. I would like just to know how it works, is it supported merely by the management of the intrinsic lock or there is something more which comes with the locks package?
I know I should go through the source code However I am running out of time (in preparing the exam). So if somebody knows in short how it works and has time to share it responding to this question, thanks in advance.
 
Henry Wong
author
Sheriff
Posts: 23603
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nick Widelec wrote:

Henry Wong wrote:
Yes, it is possible to have more than one Condition variable with the same lock. However, I am not sure of your question -- why should this not be possible?

Henry



Hi Henry,
I am not saying that it is impossible, or why it is possible or anything. I would like just to know how it works, is it supported merely by the management of the intrinsic lock or there is something more which comes with the locks package?
I know I should go through the source code However I am running out of time (in preparing the exam). So if somebody knows in short how it works and has time to share it responding to this question, thanks in advance.



How would this knowledge help with the exam?? Well... okay...

Condition variables are highly integrated with it corresponding Mutex lock. In this case, the Condition class is highly integrated with the ReentrantLock class. Obviously, the reason for this is because condition variables do things with the lock that can't be done with the public interface -- such as release all the nested locks atomically.

As an implementation detail, The ReentrantLock class (along with it's Condition Class) do not use the Java synchronization mechanism. Instead it use the atomic classes, which in turn, uses JNI to get to features based around the processor's CAS operator. As an FYI, the CAS operator is what synchronization is implemented with, so the Lock/Condition classes goes even lower than synchronization to be implemented.


Interestingly, the last time that I checked, the Lock/Condition classes doesn't use the underlying mutex/condition variables of the operating system either -- instead choosing to go to the CAS operator directly. In my opinion, this was likely a bad idea, as most OSes support priority inheritance with mutex locks, which currently, I don't think is supported by the ReentrantLock class (perhaps it can be implemented in the future).

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!