Skip to content

Commit 4c119ee

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Static import methods from Executors and MoreExecutors.
RELNOTES=n/a PiperOrigin-RevId: 782057653
1 parent 77e97c8 commit 4c119ee

File tree

66 files changed

+188
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+188
-176
lines changed

android/guava-testlib/src/com/google/common/util/concurrent/testing/AbstractListenableFutureTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.common.util.concurrent.testing;
1818

19+
import static java.util.concurrent.Executors.newCachedThreadPool;
20+
import static java.util.concurrent.Executors.newSingleThreadExecutor;
1921
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2022
import static java.util.concurrent.TimeUnit.SECONDS;
2123
import static org.junit.Assert.assertThrows;
@@ -26,7 +28,6 @@
2628
import java.util.concurrent.CountDownLatch;
2729
import java.util.concurrent.ExecutionException;
2830
import java.util.concurrent.ExecutorService;
29-
import java.util.concurrent.Executors;
3031
import java.util.concurrent.Future;
3132
import java.util.concurrent.TimeUnit;
3233
import java.util.concurrent.TimeoutException;
@@ -71,7 +72,7 @@ public void testGetBlocksUntilValueAvailable() throws Throwable {
7172
assertFalse(future.isDone());
7273
assertFalse(future.isCancelled());
7374

74-
ExecutorService executor = Executors.newSingleThreadExecutor();
75+
ExecutorService executor = newSingleThreadExecutor();
7576

7677
try {
7778
Future<Boolean> getResult = executor.submit(() -> future.get());
@@ -138,7 +139,7 @@ public void testListenersNotifiedOnError() throws Exception {
138139
CountDownLatch successLatch = new CountDownLatch(1);
139140
CountDownLatch listenerLatch = new CountDownLatch(1);
140141

141-
ExecutorService exec = Executors.newCachedThreadPool();
142+
ExecutorService exec = newCachedThreadPool();
142143

143144
future.addListener(listenerLatch::countDown, exec);
144145

@@ -171,7 +172,7 @@ public void testListenersNotifiedOnError() throws Exception {
171172
public void testAllListenersCompleteSuccessfully()
172173
throws InterruptedException, ExecutionException {
173174

174-
ExecutorService exec = Executors.newCachedThreadPool();
175+
ExecutorService exec = newCachedThreadPool();
175176

176177
int listenerCount = 20;
177178
CountDownLatch listenerLatch = new CountDownLatch(listenerCount);

android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.common.util.concurrent.testing;
1818

1919
import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService;
20+
import static java.util.concurrent.Executors.callable;
2021

2122
import com.google.common.annotations.GwtIncompatible;
2223
import com.google.common.base.Preconditions;
@@ -31,7 +32,6 @@
3132
import java.util.concurrent.Callable;
3233
import java.util.concurrent.Delayed;
3334
import java.util.concurrent.ExecutionException;
34-
import java.util.concurrent.Executors;
3535
import java.util.concurrent.Future;
3636
import java.util.concurrent.TimeUnit;
3737
import java.util.concurrent.TimeoutException;
@@ -136,7 +136,7 @@ public void execute(Runnable command) {
136136
public ListenableScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
137137
Preconditions.checkNotNull(command, "command must not be null");
138138
Preconditions.checkNotNull(unit, "unit must not be null!");
139-
return schedule(Executors.callable(command), delay, unit);
139+
return schedule(callable(command), delay, unit);
140140
}
141141

142142
@Override

android/guava-testlib/test/com/google/common/testing/FakeTickerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.common.testing;
1818

1919
import static com.google.common.testing.ReflectionFreeAssertThrows.assertThrows;
20+
import static java.util.concurrent.Executors.newFixedThreadPool;
2021
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2122
import static java.util.concurrent.TimeUnit.NANOSECONDS;
2223
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -27,7 +28,6 @@
2728
import java.util.concurrent.Callable;
2829
import java.util.concurrent.CountDownLatch;
2930
import java.util.concurrent.ExecutorService;
30-
import java.util.concurrent.Executors;
3131
import java.util.concurrent.Future;
3232
import java.util.concurrent.TimeUnit;
3333
import junit.framework.TestCase;
@@ -166,7 +166,7 @@ public void testConcurrentAutoIncrementStep() throws Exception {
166166
@GwtIncompatible // concurrency
167167
private void runConcurrentTest(int numberOfThreads, Callable<@Nullable Void> callable)
168168
throws Exception {
169-
ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
169+
ExecutorService executorService = newFixedThreadPool(numberOfThreads);
170170
CountDownLatch startLatch = new CountDownLatch(numberOfThreads);
171171
CountDownLatch doneLatch = new CountDownLatch(numberOfThreads);
172172
for (int i = numberOfThreads; i > 0; i--) {

android/guava-tests/benchmark/com/google/common/collect/ConcurrentHashMultisetBenchmark.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
2121
import static com.google.common.collect.Lists.newArrayListWithExpectedSize;
22+
import static java.util.concurrent.Executors.newFixedThreadPool;
2223

2324
import com.google.caliper.BeforeExperiment;
2425
import com.google.caliper.Benchmark;
@@ -36,7 +37,6 @@
3637
import java.util.concurrent.ConcurrentMap;
3738
import java.util.concurrent.ExecutionException;
3839
import java.util.concurrent.ExecutorService;
39-
import java.util.concurrent.Executors;
4040
import java.util.concurrent.Future;
4141
import org.jspecify.annotations.NullUnmarked;
4242
import org.jspecify.annotations.Nullable;
@@ -68,8 +68,7 @@ void setUp() throws Exception {
6868
builder.add(i);
6969
}
7070
keys = builder.build();
71-
threadPool =
72-
Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setDaemon(true).build());
71+
threadPool = newFixedThreadPool(threads, new ThreadFactoryBuilder().setDaemon(true).build());
7372
}
7473

7574
@Benchmark

android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static com.google.common.cache.TestingRemovalListeners.queuingRemovalListener;
2525
import static com.google.common.cache.TestingWeighers.constantWeigher;
2626
import static com.google.common.truth.Truth.assertThat;
27+
import static java.util.concurrent.Executors.newFixedThreadPool;
2728
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2829
import static java.util.concurrent.TimeUnit.NANOSECONDS;
2930
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -43,7 +44,6 @@
4344
import java.util.Set;
4445
import java.util.concurrent.CountDownLatch;
4546
import java.util.concurrent.ExecutorService;
46-
import java.util.concurrent.Executors;
4747
import java.util.concurrent.Future;
4848
import java.util.concurrent.atomic.AtomicBoolean;
4949
import java.util.concurrent.atomic.AtomicInteger;
@@ -445,7 +445,7 @@ public void testRemovalNotification_clear_basher() throws InterruptedException {
445445
computationShouldWait.set(true);
446446

447447
AtomicInteger computedCount = new AtomicInteger();
448-
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
448+
ExecutorService threadPool = newFixedThreadPool(nThreads);
449449
CountDownLatch tasksFinished = new CountDownLatch(nTasks);
450450
for (int i = 0; i < nTasks; i++) {
451451
String s = "a" + i;
@@ -545,7 +545,7 @@ public String load(String key) throws InterruptedException {
545545
.maximumSize(5000)
546546
.build(countingIdentityLoader);
547547

548-
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
548+
ExecutorService threadPool = newFixedThreadPool(nThreads);
549549
for (int i = 0; i < nTasks; i++) {
550550
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
551551
Future<?> possiblyIgnoredError =

android/guava-tests/test/com/google/common/collect/ConcurrentHashMultisetBasherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.collect.Lists.newArrayListWithExpectedSize;
2020
import static com.google.common.collect.Lists.transform;
2121
import static java.lang.Math.min;
22+
import static java.util.concurrent.Executors.newFixedThreadPool;
2223

2324
import com.google.common.base.Function;
2425
import com.google.common.primitives.Ints;
@@ -30,7 +31,6 @@
3031
import java.util.concurrent.ConcurrentSkipListMap;
3132
import java.util.concurrent.ExecutionException;
3233
import java.util.concurrent.ExecutorService;
33-
import java.util.concurrent.Executors;
3434
import java.util.concurrent.Future;
3535
import java.util.concurrent.atomic.AtomicInteger;
3636
import junit.framework.TestCase;
@@ -70,7 +70,7 @@ private void testAddAndRemove(ConcurrentMap<String, AtomicInteger> map)
7070
int nThreads = 20;
7171
int tasksPerThread = 10;
7272
int nTasks = nThreads * tasksPerThread;
73-
ExecutorService pool = Executors.newFixedThreadPool(nThreads);
73+
ExecutorService pool = newFixedThreadPool(nThreads);
7474
ImmutableList<String> keys = ImmutableList.of("a", "b", "c");
7575
try {
7676
List<Future<int[]>> futures = newArrayListWithExpectedSize(nTasks);

android/guava-tests/test/com/google/common/eventbus/EventBusTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.common.eventbus;
1818

19+
import static java.util.concurrent.Executors.newFixedThreadPool;
1920
import static org.junit.Assert.assertThrows;
2021

2122
import com.google.common.collect.ImmutableList;
@@ -24,7 +25,6 @@
2425
import java.util.List;
2526
import java.util.concurrent.CopyOnWriteArrayList;
2627
import java.util.concurrent.ExecutorService;
27-
import java.util.concurrent.Executors;
2828
import java.util.concurrent.Future;
2929
import java.util.concurrent.atomic.AtomicInteger;
3030
import junit.framework.TestCase;
@@ -233,7 +233,7 @@ public void testUnregister() {
233233
public void testRegisterThreadSafety() throws Exception {
234234
List<StringCatcher> catchers = new CopyOnWriteArrayList<>();
235235
List<Future<?>> futures = new ArrayList<>();
236-
ExecutorService executor = Executors.newFixedThreadPool(10);
236+
ExecutorService executor = newFixedThreadPool(10);
237237
int numberOfCatchers = 10000;
238238
for (int i = 0; i < numberOfCatchers; i++) {
239239
futures.add(executor.submit(new Registrator(bus, catchers)));

android/guava-tests/test/com/google/common/io/MoreFilesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static com.google.common.truth.Truth.assertThat;
2424
import static java.nio.charset.StandardCharsets.UTF_8;
2525
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
26+
import static java.util.concurrent.Executors.newSingleThreadExecutor;
2627
import static org.junit.Assert.assertThrows;
2728

2829
import com.google.common.collect.ObjectArrays;
@@ -43,7 +44,6 @@
4344
import java.nio.file.attribute.FileTime;
4445
import java.util.EnumSet;
4546
import java.util.concurrent.ExecutorService;
46-
import java.util.concurrent.Executors;
4747
import java.util.concurrent.Future;
4848
import junit.framework.TestCase;
4949
import org.jspecify.annotations.NullUnmarked;
@@ -577,7 +577,7 @@ public void testDirectoryDeletion_directorySymlinkRace() throws IOException {
577577
Path changingFile = dirToDelete.resolve("j/l");
578578
Path symlinkTarget = fs.getPath("/dontdelete");
579579

580-
ExecutorService executor = Executors.newSingleThreadExecutor();
580+
ExecutorService executor = newSingleThreadExecutor();
581581
startDirectorySymlinkSwitching(changingFile, symlinkTarget, executor);
582582

583583
try {

android/guava-tests/test/com/google/common/util/concurrent/AbstractClosingFutureTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
2626
import static com.google.common.util.concurrent.Futures.immediateFuture;
2727
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
28+
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
2829
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
2930
import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly;
3031
import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly;
@@ -97,8 +98,7 @@ public void fail(AssertionError failure) {
9798
}
9899
});
99100

100-
final ListeningExecutorService executor =
101-
MoreExecutors.listeningDecorator(newSingleThreadExecutor());
101+
final ListeningExecutorService executor = listeningDecorator(newSingleThreadExecutor());
102102
final ExecutorService closingExecutor = newSingleThreadExecutor();
103103

104104
final TestCloseable closeable1 = new TestCloseable("closeable1");

android/guava-tests/test/com/google/common/util/concurrent/AbstractExecutionThreadServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.common.util.concurrent;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static java.util.concurrent.Executors.newSingleThreadExecutor;
2021
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2122
import static org.junit.Assert.assertThrows;
2223

@@ -27,7 +28,6 @@
2728
import java.util.concurrent.CountDownLatch;
2829
import java.util.concurrent.Executor;
2930
import java.util.concurrent.ExecutorService;
30-
import java.util.concurrent.Executors;
3131
import java.util.concurrent.ScheduledExecutorService;
3232
import java.util.concurrent.TimeoutException;
3333
import junit.framework.TestCase;
@@ -379,7 +379,7 @@ protected String serviceName() {
379379

380380
private class FakeService extends AbstractExecutionThreadService implements TearDown {
381381

382-
private final ExecutorService executor = Executors.newSingleThreadExecutor();
382+
private final ExecutorService executor = newSingleThreadExecutor();
383383

384384
FakeService() {
385385
tearDownStack.addTearDown(this);

0 commit comments

Comments
 (0)