Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Java FAQ: Top Questions

55. What is the Exchanger class in Java?

Exchanger in java.util.concurrent is a synchronization point where two threads can exchange objects, blocking until both arrive.

  • Exchange: exchange(V x) swaps objects between threads.
  • Blocking: Waits for the other thread, with optional timeout.
  • Use Case: Producer-consumer scenarios, genetic algorithms.
  • Limitations: Only supports two threads.