@@ -0,0 +1,1610 @@
+package learn_to_code.java_api.concurency.synchronization;%0A%0Aimport java.util.concurrent.Exchanger;%0A%0A/**%0A * An example of Exchanger usage.%0A *%0A * We create 2 threads which will exchange their string via Exchanger. First thread will start with 'Hello' string, another%0A * will start with 'World' string. After 1 second, threads will exchange their strings and print out the result.%0A */%0Apublic class ExchangerExample %7B%0A    public static void main(String%5B%5D args) %7B%0A        Exchanger%3CString%3E exchanger = new Exchanger%3C%3E();%0A%0A        Thread exchangerHello = new Thread(new ExchangerUser(exchanger, %22Hello%22, %22Hello_exchanger%22));%0A        Thread exchangerWorld = new Thread(new ExchangerUser(exchanger, %22World%22, %22World_exchanger%22));%0A%0A        exchangerHello.start();%0A        exchangerWorld.start();%0A    %7D%0A%7D%0A%0Aclass ExchangerUser implements Runnable %7B%0A%0A    Exchanger%3CString%3E exchanger;%0A    String exchangedString;%0A    String exchangerName;%0A    ExchangerUser(Exchanger%3CString%3E exchanger, String exchangedString, String exchangerName) %7B%0A        this.exchanger = exchanger;%0A        this.exchangedString = exchangedString;%0A        this.exchangerName = exchangerName;%0A    %7D%0A    @Override%0A    public void run() %7B%0A        try %7B%0A            System.out.println(exchangerName + %22 has string: %22 + exchangedString);%0A            Thread.sleep(2000);%0A            String strFromAnotherExchanger = exchanger.exchange(exchangedString);%0A            System.out.println(exchangerName + %22 got string from another exchanger: %22 + strFromAnotherExchanger);%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%7D

Add Exchanger example