0

我的环境有 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 属性?

运行:INS1 运行时。信息:在 350 毫秒内连接

信息:在 16 毫秒内连接

信息:在 15 毫秒内连接

信息:在 17 毫秒内连接

信息:在 15 毫秒内连接

信息:在 16 毫秒内建立成功(总时间:0 秒)

运行:当 INS1 关闭时。信息:在 1,380 毫秒内连接

信息:在 1,060 毫秒内连接

信息:在 1,058 毫秒内连接

信息:在 1,060 毫秒内连接

信息:在 1,055 毫秒内连接

信息:在 1,041 毫秒内建立成功(总时间:6 秒)

4

1 回答 1

2

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

于 2012-11-15T04:38:33.350 回答