Skip to content

Commit e7e9ae6

Browse files
Eliminate the statement execution thread pool (#582)
Change it to same-thread executor because the main thread is anyways waiting on the task.
1 parent 4b80c3d commit e7e9ae6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/main/java/com/databricks/jdbc/api/impl/DatabricksStatement.java

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

33
import static com.databricks.jdbc.common.DatabricksJdbcConstants.*;
44
import static com.databricks.jdbc.common.EnvironmentVariables.*;
5-
import static java.lang.Runtime.getRuntime;
65
import static java.lang.String.format;
76

87
import com.databricks.jdbc.api.IDatabricksResultSet;
@@ -20,6 +19,7 @@
2019
import com.databricks.jdbc.log.JdbcLogger;
2120
import com.databricks.jdbc.log.JdbcLoggerFactory;
2221
import com.google.common.annotations.VisibleForTesting;
22+
import com.google.common.util.concurrent.MoreExecutors;
2323
import java.sql.*;
2424
import java.util.Collections;
2525
import java.util.HashMap;
@@ -31,9 +31,8 @@ public class DatabricksStatement implements IDatabricksStatement, IDatabricksSta
3131

3232
private static final JdbcLogger LOGGER = JdbcLoggerFactory.getLogger(DatabricksStatement.class);
3333

34-
/** ExecutorService for handling asynchronous execution of statements. */
35-
private final ExecutorService executor =
36-
Executors.newFixedThreadPool(getRuntime().availableProcessors() * 2);
34+
/** Same-Thread-ExecutorService for handling execution of statements. */
35+
private final ExecutorService executor = MoreExecutors.newDirectExecutorService();
3736

3837
private int timeoutInSeconds;
3938
private final DatabricksConnection connection;
@@ -646,9 +645,7 @@ void checkIfClosed() throws DatabricksSQLException {
646645
*
647646
* <p>Initiates an orderly shutdown of the executor, waiting up to 60 seconds for currently
648647
* executing tasks to terminate. If the executor does not terminate within the timeout, it is
649-
* forcefully shut down. This method is called when the statement is closed to ensure that all
650-
* threads are properly terminated, preventing the JVM from hanging due to lingering non-daemon
651-
* threads.
648+
* forcefully shut down.
652649
*/
653650
private void shutDownExecutor() {
654651
executor.shutdown();

0 commit comments

Comments
 (0)