JavaAdvanced#concurrency

Explain wait(), notify() and notifyAll().

Object methods used for inter-thread communication. wait() releases the monitor and pauses the thread. notify() wakes one waiting thread, notifyAll() wakes all. Must be called inside a synchronized block.

Example
synchronized (lock) {
  while (!ready) lock.wait();
  // proceed once notified
}
// on the other thread:
synchronized (lock) { ready = true; lock.notifyAll(); }

Related Questions

1
JavaAdvanced#design-patterns

What is the Singleton pattern? How to implement it thread-safely?

Open
2
JavaIntermediate#design-patterns#spring

What is dependency injection?

Open
3
JavaBeginner#exceptions

What is the difference between throw and throws?

Open