Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Jul 12, 2024
1 parent 429ae6f commit 0421484
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public final class Constants {
private Constants() {
}

public static final String BALLERINA_MAX_POOL_SIZE = "BALLERINA_MAX_POOL_SIZE";
public static final String CONNECTOR_NAME = "SQLClientConnector";
public static final String DATABASE_CLIENT = "Client";
public static final String DATABASE_CLIENT_ACTIVE_STATUS = "clientActive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.stdlib.sql.datasource;

import io.ballerina.stdlib.sql.Constants;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
Expand All @@ -32,11 +34,10 @@ public class SQLWorkerThreadPool {
private SQLWorkerThreadPool() {
}

// Read the pool size from a system property, defaulting to 50 if not set
private static final int POOL_SIZE = Integer.parseInt(System.getProperty("BALLERINA_SQL_THREAD_POOL_SIZE", "50"));
static final int maxPoolSize = Integer.parseInt(System.getProperty(Constants.BALLERINA_MAX_POOL_SIZE, "50"));

// This is similar to cachedThreadPool util from Executors.newCachedThreadPool(..); but with upper cap on threads
public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, POOL_SIZE,
public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, maxPoolSize,
60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new SQLThreadFactory());

static class SQLThreadFactory implements ThreadFactory {
Expand Down

0 comments on commit 0421484

Please sign in to comment.