gpt4 book ai didi

java - JDBC MySQL 连接到故障转移节点非常慢

转载 作者:行者123 更新时间:2023-11-29 08:42:35 25 4
gpt4 key购买 nike

我的环境有 2 个 MySQL 服务器(INS1 和 INS2),当我在 INS1 关闭且驱动程序创建到 INS2 的连接的情况下测试故障转移模式时,连接速度非常慢(Glassfish 连接池上也出现过这种情况。)

final String connstr = "jdbc:mysql://INS1,INS2:3306/mysql";
Properties props = new Properties();
props.put("user", "xxx");
props.put("password", "xxx");
props.put("failOverReadOnly", "false");
props.put("roundRobinLoadBalance", "false");

return DriverManager.getConnection(connstr, props);

如何调整jdbc属性?

run: When INS1 run. INFO: Connected in 350 ms

INFO: Connected in 16 ms

INFO: Connected in 15 ms

INFO: Connected in 17 ms

INFO: Connected in 15 ms

INFO: Connected in 16 ms BUILD SUCCESSFUL (total time: 0 seconds)

run: When INS1 down. INFO: Connected in 1,380 ms

INFO: Connected in 1,060 ms

INFO: Connected in 1,058 ms

INFO: Connected in 1,060 ms

INFO: Connected in 1,055 ms

INFO: Connected in 1,041 ms BUILD SUCCESSFUL (total time: 6 seconds)

最佳答案

//socket连接超时(以毫秒为单位),0表示不超时。仅适用于 JDK-1.4 或更高版本。默认为“0”。props.put("connectTimeout", "100");

关于java - JDBC MySQL 连接到故障转移节点非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com