Class ConditionVariable
- java.lang.Object
-
- com.google.android.exoplayer2.util.ConditionVariable
-
@Deprecated public class ConditionVariable extends Object
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.An interruptible condition variable. This class provides a number of benefits overConditionVariable:- Consistent use of (
Clock.elapsedRealtime()for timingblock(long)timeout intervals.ConditionVariableusedSystem.currentTimeMillis()prior to Android 10, which is not a correct clock to use for interval timing because it's not guaranteed to be monotonic. - Support for injecting a custom
Clock. - The ability to query the variable's current state, by calling
isOpen(). open()andclose()return whether they changed the variable's state.
- Consistent use of (
-
-
Constructor Summary
Constructors Constructor Description ConditionVariable()Deprecated.Creates a closed instance usingClock.DEFAULT.ConditionVariable(Clock clock)Deprecated.Creates an instance, which starts closed.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidblock()Deprecated.Blocks until the condition is opened.booleanblock(long timeoutMs)Deprecated.Blocks until the condition is opened or untiltimeoutMshave passed.voidblockUninterruptible()Deprecated.Blocks until the condition is open.booleanclose()Deprecated.Closes the condition.booleanisOpen()Deprecated.Returns whether the condition is opened.booleanopen()Deprecated.Opens the condition and releases all threads that are blocked.
-
-
-
Constructor Detail
-
ConditionVariable
public ConditionVariable()
Deprecated.Creates a closed instance usingClock.DEFAULT.
-
ConditionVariable
public ConditionVariable(Clock clock)
Deprecated.Creates an instance, which starts closed.- Parameters:
clock- TheClockwhoseClock.elapsedRealtime()method is used to determine whenblock(long)should time out.
-
-
Method Detail
-
open
public boolean open()
Deprecated.Opens the condition and releases all threads that are blocked.- Returns:
- True if the condition variable was opened. False if it was already open.
-
close
public boolean close()
Deprecated.Closes the condition.- Returns:
- True if the condition variable was closed. False if it was already closed.
-
block
public void block() throws InterruptedExceptionDeprecated.Blocks until the condition is opened.- Throws:
InterruptedException- If the thread is interrupted.
-
block
public boolean block(long timeoutMs) throws InterruptedExceptionDeprecated.Blocks until the condition is opened or untiltimeoutMshave passed.- Parameters:
timeoutMs- The maximum time to wait in milliseconds. IftimeoutMs <= 0then the call will return immediately without blocking.- Returns:
- True if the condition was opened, false if the call returns because of the timeout.
- Throws:
InterruptedException- If the thread is interrupted.
-
blockUninterruptible
public void blockUninterruptible()
Deprecated.Blocks until the condition is open. Unlikeblock(), this method will continue to block if the calling thread is interrupted. If the calling thread was interrupted then itsinterrupted statuswill be set when the method returns.
-
isOpen
public boolean isOpen()
Deprecated.Returns whether the condition is opened.
-
-