Skip to content

Commit 6765ee7

Browse files
committed
fix shutdown
1 parent c0278c6 commit 6765ee7

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,14 +964,38 @@ private void closeImpl() throws SQLException {
964964

965965
if (this.metadataExecutor != null) {
966966
this.metadataExecutor.shutdown();
967-
this.metadataExecutor.awaitTermination(10, TimeUnit.SECONDS);
968-
this.metadataExecutor.shutdownNow();
969967
}
970-
971968
if (this.queryExecutor != null) {
972969
this.queryExecutor.shutdown();
973-
this.queryExecutor.awaitTermination(10, TimeUnit.SECONDS);
974-
this.queryExecutor.shutdownNow();
970+
}
971+
972+
boolean interrupted = false;
973+
974+
if (this.metadataExecutor != null) {
975+
try {
976+
if (!this.metadataExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
977+
this.metadataExecutor.shutdownNow();
978+
}
979+
} catch (InterruptedException e) {
980+
this.metadataExecutor.shutdownNow();
981+
interrupted = true;
982+
}
983+
}
984+
985+
if (this.queryExecutor != null) {
986+
try {
987+
if (!this.queryExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
988+
this.queryExecutor.shutdownNow();
989+
}
990+
} catch (InterruptedException e) {
991+
this.queryExecutor.shutdownNow();
992+
interrupted = true;
993+
}
994+
}
995+
996+
if (interrupted) {
997+
Thread.currentThread().interrupt();
998+
throw new InterruptedException("Interrupted awaiting executor termination");
975999
}
9761000
} catch (ConcurrentModificationException ex) {
9771001
throw new BigQueryJdbcException("Concurrent modification during close", ex);

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/DataSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,11 @@ private static void validateNonNegative(long val, String propertyName) {
14131413
}
14141414
}
14151415

1416+
/**
1417+
* Validates that a property value is greater than or equal to a minimum threshold.
1418+
* For thread pools, a minimum of 2 is enforced to ensure there are enough threads
1419+
* to handle concurrent coordination and avoid deadlock or thread starvation.
1420+
*/
14161421
private static void validateMin(long val, long min, String propertyName) {
14171422
if (val < min) {
14181423
throw new BigQueryJdbcRuntimeException(

0 commit comments

Comments
 (0)