Skip to content

Check for Common FJP Having Zero Threads #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/oracle/r2dbc/OracleR2dbcOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ private OracleR2dbcOptions() {}
* ...
* .build();
* </pre>
* If this option is not configured, then Oracle R2DBC will use
* {@code ForkJoinPool}'s
* {@linkplain ForkJoinPool#commonPool() common pool} by default.
* If this option is not configured, then Oracle R2DBC will
* use the {@linkplain ForkJoinPool#commonPool() common ForkJoinPool} by
* default. However, if the common {@code ForkJoinPool} has a maximum pool
* size that is potentially zero, then a single-threaded {@code Executor} will
* be used by default.
*/
public static final Option<Executor> EXECUTOR;

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/oracle/r2dbc/impl/OracleConnectionFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@
*/
final class OracleConnectionFactoryImpl implements ConnectionFactory {

/**
* <p>
* The default executor when {@link OracleR2dbcOptions#EXECUTOR} is not
* configured. It will use the common {@code ForkJoinPool}, unless it has
* a maximum pool size of 0. See:
* https://github.com/oracle/oracle-r2dbc/issues/129
* </p>
*/
private static final Executor DEFAULT_EXECUTOR =
"0".equals(System.getProperty(
"java.util.concurrent.ForkJoinPool.common.parallelism"))
? new ForkJoinPool(1)
: ForkJoinPool.commonPool();

/** JDBC data source that this factory uses to open connections */
private final DataSource dataSource;

Expand Down Expand Up @@ -200,7 +214,7 @@ final class OracleConnectionFactoryImpl implements ConnectionFactory {

Object executor = options.getValue(OracleR2dbcOptions.EXECUTOR);
if (executor == null) {
this.executor = ForkJoinPool.commonPool();
this.executor = DEFAULT_EXECUTOR;
}
else if (executor instanceof Executor) {
this.executor = (Executor) executor;
Expand Down Expand Up @@ -267,4 +281,5 @@ public Publisher<Connection> create() {
public ConnectionFactoryMetadata getMetadata() {
return () -> "Oracle Database";
}

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

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

Expand Down