to top
Android APIs
public class

ConditionVariable

extends Object
java.lang.Object
   ↳ android.os.ConditionVariable

Class Overview

Class that implements the condition variable locking paradigm.

This differs from the built-in java.lang.Object wait() and notify() in that this class contains the condition to wait on itself. That means open(), close() and block() are sticky. If open() is called before block(), block() will not block, and instead return immediately.

This class uses itself as the object to wait on, so if you wait() or notify() on a ConditionVariable, the results are undefined.

Summary

Public Constructors

? Examples
ConditionVariable()
Create the ConditionVariable in the default closed state.

? Examples
ConditionVariable(boolean state)
Create the ConditionVariable with the given state.
Public Methods

? Examples
boolean block(long timeout)
Block the current thread until the condition is opened or until timeout milliseconds have passed.

? Examples
void block()
Block the current thread until the condition is opened.

? Examples
void close()
Reset the condition to the closed state.

? Examples
void open()
Open the condition, and release all threads that are blocked.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ConditionVariable ()

Added in API level 1

Create the ConditionVariable in the default closed state.

public ConditionVariable (boolean state)

Added in API level 1

Create the ConditionVariable with the given state.

Pass true for opened and false for closed.

Public Methods

public boolean block (long timeout)

Added in API level 1

Block the current thread until the condition is opened or until timeout milliseconds have passed.

If the condition is already opened, return immediately.

Parameters
timeout the minimum time to wait in milliseconds.
Returns
  • true if the condition was opened, false if the call returns because of the timeout.

public void block ()

Added in API level 1

Block the current thread until the condition is opened.

If the condition is already opened, return immediately.

public void close ()

Added in API level 1

Reset the condition to the closed state.

Any threads that call block() will block until someone calls open.

public void open ()

Added in API level 1

Open the condition, and release all threads that are blocked.

Any threads that later approach block() will not block unless close() is called.

No examples for this method.
Frequently called with: [Clear]
Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License. The original page is available here.