Share via


Exchanger.Exchange Method

Definition

Overloads

Exchange(Object)

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted), and then transfers the given object to it, receiving its object in return.

Exchange(Object, Int64, TimeUnit)

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted or the specified waiting time elapses), and then transfers the given object to it, receiving its object in return.

Exchange(Object)

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted), and then transfers the given object to it, receiving its object in return.

[Android.Runtime.Register("exchange", "(Ljava/lang/Object;)Ljava/lang/Object;", "GetExchange_Ljava_lang_Object_Handler")]
public virtual Java.Lang.Object? Exchange (Java.Lang.Object? x);
[<Android.Runtime.Register("exchange", "(Ljava/lang/Object;)Ljava/lang/Object;", "GetExchange_Ljava_lang_Object_Handler")>]
abstract member Exchange : Java.Lang.Object -> Java.Lang.Object
override this.Exchange : Java.Lang.Object -> Java.Lang.Object

Parameters

x
Object

the object to exchange

Returns

the object provided by the other thread

Attributes

Remarks

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted), and then transfers the given object to it, receiving its object in return.

If another thread is already waiting at the exchange point then it is resumed for thread scheduling purposes and receives the object passed in by the current thread. The current thread returns immediately, receiving the object passed to the exchange by that other thread.

If no other thread is already waiting at the exchange then the current thread is disabled for thread scheduling purposes and lies dormant until one of two things happens: <ul> <li>Some other thread enters the exchange; or <li>Some other thread Thread#interrupt interrupts the current thread. </ul>

If the current thread: <ul> <li>has its interrupted status set on entry to this method; or <li>is Thread#interrupt interrupted while waiting for the exchange, </ul> then InterruptedException is thrown and the current thread's interrupted status is cleared.

Java documentation for java.util.concurrent.Exchanger.exchange(V).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exchange(Object, Int64, TimeUnit)

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted or the specified waiting time elapses), and then transfers the given object to it, receiving its object in return.

[Android.Runtime.Register("exchange", "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;", "GetExchange_Ljava_lang_Object_JLjava_util_concurrent_TimeUnit_Handler")]
public virtual Java.Lang.Object? Exchange (Java.Lang.Object? x, long timeout, Java.Util.Concurrent.TimeUnit? unit);
[<Android.Runtime.Register("exchange", "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;", "GetExchange_Ljava_lang_Object_JLjava_util_concurrent_TimeUnit_Handler")>]
abstract member Exchange : Java.Lang.Object * int64 * Java.Util.Concurrent.TimeUnit -> Java.Lang.Object
override this.Exchange : Java.Lang.Object * int64 * Java.Util.Concurrent.TimeUnit -> Java.Lang.Object

Parameters

x
Object

the object to exchange

timeout
Int64

the maximum time to wait

unit
TimeUnit

the time unit of the timeout argument

Returns

the object provided by the other thread

Attributes

Remarks

Waits for another thread to arrive at this exchange point (unless the current thread is Thread#interrupt interrupted or the specified waiting time elapses), and then transfers the given object to it, receiving its object in return.

If another thread is already waiting at the exchange point then it is resumed for thread scheduling purposes and receives the object passed in by the current thread. The current thread returns immediately, receiving the object passed to the exchange by that other thread.

If no other thread is already waiting at the exchange then the current thread is disabled for thread scheduling purposes and lies dormant until one of three things happens: <ul> <li>Some other thread enters the exchange; or <li>Some other thread Thread#interrupt interrupts the current thread; or <li>The specified waiting time elapses. </ul>

If the current thread: <ul> <li>has its interrupted status set on entry to this method; or <li>is Thread#interrupt interrupted while waiting for the exchange, </ul> then InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then TimeoutException is thrown. If the time is less than or equal to zero, the method will not wait at all.

Java documentation for java.util.concurrent.Exchanger.exchange(V, long, java.util.concurrent.TimeUnit).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to