Skip to content

Commit da33589

Browse files
Merge pull request #131 from oracle/129-fjp-zero
Check for Common FJP Having Zero Threads
2 parents 2914e60 + c801c10 commit da33589

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/main/java/oracle/r2dbc/OracleR2dbcOptions.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ private OracleR2dbcOptions() {}
5656
* ...
5757
* .build();
5858
* </pre>
59-
* If this option is not configured, then Oracle R2DBC will use
60-
* {@code ForkJoinPool}'s
61-
* {@linkplain ForkJoinPool#commonPool() common pool} by default.
59+
* If this option is not configured, then Oracle R2DBC will
60+
* use the {@linkplain ForkJoinPool#commonPool() common ForkJoinPool} by
61+
* default. However, if the common {@code ForkJoinPool} has a maximum pool
62+
* size that is potentially zero, then a single-threaded {@code Executor} will
63+
* be used by default.
6264
*/
6365
public static final Option<Executor> EXECUTOR;
6466

src/main/java/oracle/r2dbc/impl/OracleConnectionFactoryImpl.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@
102102
*/
103103
final class OracleConnectionFactoryImpl implements ConnectionFactory {
104104

105+
/**
106+
* <p>
107+
* The default executor when {@link OracleR2dbcOptions#EXECUTOR} is not
108+
* configured. It will use the common {@code ForkJoinPool}, unless it has
109+
* a maximum pool size of 0. See:
110+
* https://github.com/oracle/oracle-r2dbc/issues/129
111+
* </p>
112+
*/
113+
private static final Executor DEFAULT_EXECUTOR =
114+
"0".equals(System.getProperty(
115+
"java.util.concurrent.ForkJoinPool.common.parallelism"))
116+
? new ForkJoinPool(1)
117+
: ForkJoinPool.commonPool();
118+
105119
/** JDBC data source that this factory uses to open connections */
106120
private final DataSource dataSource;
107121

@@ -200,7 +214,7 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {
200214

201215
Object executor = options.getValue(OracleR2dbcOptions.EXECUTOR);
202216
if (executor == null) {
203-
this.executor = ForkJoinPool.commonPool();
217+
this.executor = DEFAULT_EXECUTOR;
204218
}
205219
else if (executor instanceof Executor) {
206220
this.executor = (Executor) executor;
@@ -267,4 +281,5 @@ public Publisher<Connection> create() {
267281
public ConnectionFactoryMetadata getMetadata() {
268282
return () -> "Oracle Database";
269283
}
284+
270285
}

src/test/java/oracle/r2dbc/impl/OracleStatementImplTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ private void verifyConcurrentFetch(Connection connection) {
32223222
// Create many statements and execute them in parallel.
32233223
@SuppressWarnings({"unchecked","rawtypes"})
32243224
Publisher<Long>[] publishers =
3225-
new Publisher[Runtime.getRuntime().availableProcessors() * 4];
3225+
new Publisher[Runtime.getRuntime().availableProcessors() * 2];
32263226

32273227
for (int i = 0; i < publishers.length; i++) {
32283228

0 commit comments

Comments
 (0)