Code example for Exchanger

0
 
   static class MeetingPlace { 
      private final Exchanger<Agent> room;
 
      MeetingPlace() { 
         room = new Exchanger<>();
      } 
 
      public Agent enter(Agent visitor) throws InterruptedException {
         if (meetingsLeft.get() < 0) {
            return null; 
         } 
         Agent agent = room.exchange(visitor);
         latch.countDown();
         if (meetingsLeft.decrementAndGet() < 0) {
            return null; 
         } 
         return agent;
      } 
 
Connect your IDE to all the code out there  Get Codota for Java