Skip to content

Commit

Permalink
Fix #1865
Browse files Browse the repository at this point in the history
  • Loading branch information
ly641921791 committed Sep 25, 2019
1 parent 0b66b0c commit e189cca
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import io.netty.channel.ConnectTimeoutException;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.SocketTimeoutException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.List;
import java.util.concurrent.*;

Expand Down Expand Up @@ -149,17 +145,11 @@ public void run() {
AbstractHealthChecker.Mysql config = (AbstractHealthChecker.Mysql) cluster.getHealthChecker();

if (connection == null || connection.isClosed()) {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setConnectTimeout(CONNECT_TIMEOUT_MS);
dataSource.setSocketTimeout(CONNECT_TIMEOUT_MS);
dataSource.setUser(config.getUser());
dataSource.setPassword(config.getPwd());
dataSource.setLoginTimeout(1);

dataSource.setServerName(ip.getIp());
dataSource.setPort(ip.getPort());

connection = dataSource.getConnection();
String url = "jdbc:mysql://" + ip.getIp() + ":" + ip.getPort() +
"?connectTimeout=" + CONNECT_TIMEOUT_MS +
"&socketTimeout=" + CONNECT_TIMEOUT_MS +
"&loginTimeout=" + 1;
connection = DriverManager.getConnection(url, config.getUser(), config.getPwd());
CONNECTION_POOL.put(key, connection);
}

Expand Down

0 comments on commit e189cca

Please sign in to comment.