java – Is it possible to combine several synchronization methods?

Question:

Hello. I'm learning thread synchronization in Java, and as I understood from the book, there are several ways to synchronize: through the synchronized , through the use of ReentrantLock locks, and through the wait / notify .

  1. Have I identified these methods correctly?
  2. Are these methods self-sufficient? Can each of them be used without resorting to the others?
  3. Is a combination of these methods impossible/undesirable/acceptable/desirable?

Answer:

  1. synchronized, wait, notify and notifyAll work together – they are primitives. ReentrantLock is a high-level construct and is implemented through primitives.
  2. You can create high-level constructs from primitives yourself, but you have to think carefully about the architecture.
  3. Usually high-level constructs are used rather than notations, but you can mix them up if needed.
Scroll to Top