0

I'm trying to write some classes that implements the java.util.concurrent.locks.Lock interface, one of the methods that should be overridden is condition that returns a condition associated with the lock.

Is there an implementation for the java.util.concurrent.locks.Condition interface that I can use? Writing one by myself seems like a hard task

Dor Mesica
  • 507
  • 1
  • 7
  • 23

1 Answers1

0

The sources for implementations of these interfaces are all in the OpenJDK source tree. The code in AbstractQueuedSynchronizer is where the heavy lifting occurs. However, I doubt you can extract the Condition code from here and just use with your Lock implementation. My guess is that the code for locks and conditions is fairly mutually dependent.

If you only need to support mutual exclusion but not conditions, you don't have to implement them. The newCondition method says that support for conditions is optional, and this method is allowed to support UnsupportedOperationException. The ReentrantReadWriteLock.ReadLock class is an example of a lock that doesn't support conditions.

Stuart Marks
  • 127,867
  • 37
  • 205
  • 259