Skip to content

Commit

Permalink
Merge pull request #34 from alex268/release_v2.0.4
Browse files Browse the repository at this point in the history
Force using of single thread scheduler
  • Loading branch information
alex268 committed Nov 30, 2023
2 parents 378a388 + 3a5415b commit c7a2ea6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jdbc/src/main/java/tech/ydb/jdbc/context/YdbContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.SQLException;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -148,6 +149,17 @@ public static GrpcTransport buildGrpcTransport(YdbConnectionProperties props) {
builder = builder.withAuthProvider(props.getStaticCredentials());
}

// Use custom single thread scheduler because JDBC driver doesn't need to execute retries except for DISCOERY
builder.withSchedulerFactory(() -> {
final String namePrefix = "ydb-jdbc-scheduler[" + props.hashCode() +"]-thread-";
final AtomicInteger threadNumber = new AtomicInteger(1);
return Executors.newScheduledThreadPool(1, (Runnable r) -> {
Thread t = new Thread(r, namePrefix + threadNumber.getAndIncrement());
t.setDaemon(true);
return t;
});
});

return builder.build();
}

Expand Down

0 comments on commit c7a2ea6

Please sign in to comment.