September 2019
Intermediate to advanced
816 pages
18h 47m
English
An exchanger is a Java synchronizer that allows two threads to exchange objects at an exchange or synchronization point.
Mainly, this kind of synchronizer acts as a barrier. Two threads wait for each other at a barrier. They exchange an object and continue their usual tasks when both arrive.
The following diagram depicts in four steps the flow of an exchanger:

In API terms, this synchronizer is exposed by java.util.concurrent.Exchanger.
An Exchanger can be created via an empty constructor and exposes two exchange() methods: