Add utility to create ScheduledExecutorService

PiperOrigin-RevId: 538129792
(cherry picked from commit 08e7158be51324752c4ae0f3b4f723b6fae7e7a8)
This commit is contained in:
claincly 2023-06-06 10:20:51 +00:00 committed by Tofunmi Adigun-Hameed
parent a5949d8806
commit 70a25b01bf
2 changed files with 14 additions and 2 deletions

View File

@ -117,6 +117,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.DataFormatException;
@ -742,6 +743,17 @@ public final class Util {
return Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, threadName));
}
/**
* Instantiates a new single threaded scheduled executor whose thread has the specified name.
*
* @param threadName The name of the thread.
* @return The executor.
*/
@UnstableApi
public static ScheduledExecutorService newSingleThreadScheduledExecutor(String threadName) {
return Executors.newSingleThreadScheduledExecutor(runnable -> new Thread(runnable, threadName));
}
/**
* Closes a {@link Closeable}, suppressing any {@link IOException} that may occur. Both {@link
* java.io.OutputStream} and {@link InputStream} are {@code Closeable}.

View File

@ -34,7 +34,6 @@ import androidx.media3.effect.DebugTraceUtil;
import com.google.common.collect.ImmutableList;
import java.io.File;
import java.nio.ByteBuffer;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
@ -48,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
*/
/* package */ final class MuxerWrapper {
private static final String TIMER_THREAD_NAME = "Muxer:Timer";
private static final String MUXER_TIMEOUT_ERROR_FORMAT_STRING =
"Abort: no output sample written in the last %d milliseconds. DebugTrace: %s";
@ -93,7 +93,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
trackTypeToInfo = new SparseArray<>();
previousTrackType = C.TRACK_TYPE_NONE;
abortScheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
abortScheduledExecutorService = Util.newSingleThreadScheduledExecutor(TIMER_THREAD_NAME);
}
/**