Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 617996b

Browse files
committed
Default client executor server is no longer ForkJoinPool.commonPool.
Change-Id: I4790491c20b1a88b87d16c8ec796bfe9839f7d21
1 parent f538118 commit 617996b

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

core-client/src/main/java/org/glassfish/jersey/client/ClientExecutorProvidersConfigurator.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.security.AccessController;
4545
import java.util.Map;
4646
import java.util.concurrent.ExecutorService;
47-
import java.util.concurrent.ForkJoinPool;
4847
import java.util.concurrent.ScheduledExecutorService;
4948
import java.util.logging.Level;
5049
import java.util.logging.Logger;
@@ -71,6 +70,7 @@
7170
class ClientExecutorProvidersConfigurator extends AbstractExecutorProvidersConfigurator {
7271

7372
private static final Logger LOGGER = Logger.getLogger(ClientExecutorProvidersConfigurator.class.getName());
73+
private static final ExecutorService MANAGED_EXECUTOR_SERVICE = lookupManagedExecutorService();
7474

7575
private final ComponentBag componentBag;
7676
private final JerseyClient client;
@@ -92,10 +92,10 @@ public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) {
9292

9393
// if there is a users provided executor service, use it
9494
if (clientExecutorService != null) {
95-
defaultAsyncExecutorProvider = new ClientExecutorServiceProvider(Values.<ExecutorService>of(clientExecutorService));
95+
defaultAsyncExecutorProvider = new ClientExecutorServiceProvider(clientExecutorService);
9696
// otherwise, check for ClientProperties.ASYNC_THREADPOOL_SIZE - if that is set, Jersey will create the
9797
// ExecutorService to be used. If not and running on Java EE container, ManagedExecutorService will be used.
98-
// Final fallback is ForkJoinPool.commonPool()).
98+
// Final fallback is DefaultClientAsyncExecutorProvider with defined default.
9999
} else {
100100

101101
// Default async request executors support
@@ -112,13 +112,11 @@ public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) {
112112

113113
defaultAsyncExecutorProvider = new DefaultClientAsyncExecutorProvider(asyncThreadPoolSize);
114114
} else {
115-
defaultAsyncExecutorProvider = new ClientExecutorServiceProvider(Values.lazy(new Value<ExecutorService>() {
116-
@Override
117-
public ExecutorService get() {
118-
ExecutorService executorService = lookupManagedExecutorService();
119-
return executorService == null ? ForkJoinPool.commonPool() : executorService;
120-
}
121-
}));
115+
if (MANAGED_EXECUTOR_SERVICE != null) {
116+
defaultAsyncExecutorProvider = new ClientExecutorServiceProvider(MANAGED_EXECUTOR_SERVICE);
117+
} else {
118+
defaultAsyncExecutorProvider = new DefaultClientAsyncExecutorProvider(0);
119+
}
122120
}
123121
}
124122

@@ -152,7 +150,7 @@ public ExecutorService get() {
152150
registerExecutors(injectionManager, componentBag, defaultAsyncExecutorProvider, defaultScheduledExecutorProvider);
153151
}
154152

155-
private ExecutorService lookupManagedExecutorService() {
153+
private static ExecutorService lookupManagedExecutorService() {
156154
// Get the default ManagedExecutorService, if available
157155
try {
158156
// Android and some other environments don't have InitialContext class available.
@@ -200,15 +198,15 @@ private ScheduledExecutorService lookupManagedScheduledExecutorService() {
200198
@ClientAsyncExecutor
201199
public static class ClientExecutorServiceProvider implements ExecutorServiceProvider {
202200

203-
private final Value<ExecutorService> executorService;
201+
private final ExecutorService executorService;
204202

205-
ClientExecutorServiceProvider(Value<ExecutorService> executorService) {
203+
ClientExecutorServiceProvider(ExecutorService executorService) {
206204
this.executorService = executorService;
207205
}
208206

209207
@Override
210208
public ExecutorService getExecutorService() {
211-
return executorService.get();
209+
return executorService;
212210
}
213211

214212
@Override

core-client/src/main/java/org/glassfish/jersey/client/JerseyClient.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.util.Map;
4949
import java.util.concurrent.ExecutorService;
5050
import java.util.concurrent.Executors;
51-
import java.util.concurrent.ForkJoinPool;
5251
import java.util.concurrent.LinkedBlockingDeque;
5352
import java.util.concurrent.ScheduledExecutorService;
5453
import java.util.concurrent.atomic.AtomicBoolean;
@@ -304,10 +303,6 @@ private void cleanUpShutdownHooks() {
304303
}
305304
}
306305

307-
private ExecutorService getDefaultExecutorService() {
308-
return ForkJoinPool.commonPool();
309-
}
310-
311306
private ScheduledExecutorService getDefaultScheduledExecutorService() {
312307
return Executors.newScheduledThreadPool(8);
313308
}

ext/rx/rx-client-rxjava/src/test/java/org/glassfish/jersey/client/rx/rxjava/RxObservableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private static void testResponse(final Response response, final int expectedStat
223223

224224
// Executor.
225225
assertThat(response.getHeaderString("Test-Thread"), testDedicatedThread
226-
? containsString("jersey-rx-client-test") : containsString("ForkJoinPool.commonPool"));
226+
? containsString("jersey-rx-client-test") : containsString("jersey-client-async-executor"));
227227

228228
// Properties.
229229
assertThat(response.getHeaderString("Test-Uri"), is("http://jersey.java.net"));

ext/rx/rx-client-rxjava2/src/test/java/org/glassfish/jersey/client/rx/rxjava2/RxFlowableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private static void testResponse(final Response response, final int expectedStat
212212

213213
// Executor.
214214
assertThat(response.getHeaderString("Test-Thread"), testDedicatedThread
215-
? containsString("jersey-rx-client-test") : containsString("ForkJoinPool.commonPool"));
215+
? containsString("jersey-rx-client-test") : containsString("jersey-client-async-executor"));
216216

217217
// Properties.
218218
assertThat(response.getHeaderString("Test-Uri"), is("http://jersey.java.net"));

tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/ClientExecutorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void testDefaultExecutorRx() throws InterruptedException {
124124

125125
latch.await(3, TimeUnit.SECONDS);
126126
assertNotNull(threadName);
127-
assertThat(threadName, containsString("ForkJoinPool.commonPool"));
127+
assertThat(threadName, containsString("jersey-client-async-executor"));
128128
}
129129

130130
@Test
@@ -138,7 +138,7 @@ public void testDefaultExecutorAsync() throws InterruptedException {
138138

139139
latch.await(3, TimeUnit.SECONDS);
140140
assertNotNull(threadName);
141-
assertThat(threadName, containsString("ForkJoinPool.commonPool"));
141+
assertThat(threadName, containsString("jersey-client-async-executor"));
142142
}
143143

144144
@Test

0 commit comments

Comments
 (0)