ExchangerV


Exchanger<V> java.util.concurrent

Java 5.0

This class allows two threads to rendezvous and exchange data. This is a generic type, and the type variable V represents the type of data to be exchanged. Each thread should call exchange( ) and pass the value of type V that it wants to exchange. The first thread to call exchange( ) blocks until the second thread calls it. At that point, both threads resume. Both threads receive as their return value the object of type V passed by the other thread. Note that this class also defines a timed version of exchange( ) that throws a TimeoutException if no exchange occurs within the specified timeout interval. Unlike a CountDownLatch , which is a one-shot latch, and CyclicBarrier which can be "broken," an Exchanger may be reused for any number of exchanges.

 public class  Exchanger<V>  {  // Public Constructors  public  Exchanger  ( );  // Public Instance Methods  public V  exchange  (V  x  ) throws InterruptedException;        public V  exchange  (V  x  , long  timeout  , TimeUnit  unit  )          throws InterruptedException, TimeoutException;   } 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net