TESB-18908:Memory-Leak in TalendDataSource implementation (#864)

This commit is contained in:
SunChaoqun
2017-03-17 14:59:34 +08:00
committed by wang wei
parent f167df7f13
commit 7997edd95e

View File

@@ -2,15 +2,11 @@ package routines.system;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
public class TalendDataSource {
private final javax.sql.DataSource ds;
private Set<Connection> conns = new HashSet<>();
/**
* hold a data source inside
*
@@ -28,10 +24,8 @@ public class TalendDataSource {
*/
public java.sql.Connection getConnection() throws SQLException {
Connection conn = ds.getConnection();
if (conn != null) {
conns.add(conn);
} else {
throw new RuntimeException("Unable to get a pooled database connection from pool");
if (conn == null) {
throw new RuntimeException("Unable to get a pooled database connection from pool");
}
return conn;
}
@@ -44,18 +38,4 @@ public class TalendDataSource {
public javax.sql.DataSource getRawDataSource() {
return ds;
}
/**
* close all the connections which is created by the data source inside
*
* @throws SQLException
*/
public void close() throws SQLException {
for (Connection conn : conns) {
if (!conn.isClosed()) {// the connection can be closed outside
conn.close();
}
}
conns.clear();
}
}