Webアプリケーションでproxool接続プールを使用してjdbc接続を取得しようとしています。コードの下に同じことを説明します。私は私のサーバーを起動すると何が起こることは、すぐにある接続プール使用時の同時変更
public static Connection getConnection(String key, boolean useConnectionPool, String poolName) {
Connection connection = null;
String alias = "DBCP" + poolName + "_" + key;
String driverClass = "com.mysql.jdbc.Driver";
checkAndLoadProps();
String driverUrl = "jdbc:mysql://" + props.getProperty(key + "_DBMS_URL") + "/" + props.getProperty(key + "_DEF_SCHEMA") + "?autoReconnect=true&useUnicode=true&characterEncoding=utf8&jdbcCompliantTruncation=false&rewriteBatchedStatement=true";
String connectionPoolUrl = "proxool." + alias + ":" + driverClass + ":" + driverUrl;
try {
if (useConnectionPool) {
info.remove("user");
String user = props.getProperty(key + "_CLIENT");
info.setProperty("user", user);
info.remove("password");
String password = props.getProperty(key + "_CLIENT_PASS");
info.setProperty("password", password);
String host = props.getProperty(key + "_DBMS_URL");
synchronized (poolName) {
connection = DriverManager.getConnection(connectionPoolUrl, info);
}
}
if (connection != null) {
return connection;
} else {
System.out.println("DB Connection Not Established");
}
} catch (Exception ex) {
System.out.println("DB Connection Not Established::" + ex.getMessage());
ex.printStackTrace();
}
return null;
}
、1つの以上のスレッドが並列にこのコードにアクセスしようとすると、それは同時変更例外がスローされます。
同期ブロックにクラスレベルのロックを設定することで修正できることを理解します。しかし、それはパフォーマンスに深刻な影響を与えます。
もっと良い解決法はありますか?
あなたはスタックトレースを追加してくださいだろうか? –
'info 'の定義方法も表示してください –