Created attachment 34766 [details] the method "getPreparedStatement" in class AbstractJDBCTestElement. Encounter OOM when using jdbcsampler concurrently. Looking into the dump with hat, I find object "perConnCache" held a lot of retained heap. (Sorry for not saving the dump file) Following is the definition of perConnCache in class AbstractJDBCTestElement _____________________________________CODE___________________________________ /** * Cache of PreparedStatements stored in a per-connection basis. Each entry of this * cache is another Map mapping the statement string to the actual PreparedStatement. * At one time a Connection is only held by one thread */ private static final Map<Connection, Map<String, PreparedStatement>> perConnCache = new ConcurrentHashMap<Connection, Map<String, PreparedStatement>>(); ____________________________________________________________________________ The param "connection" is from the method "getConnection()" which in DBCP2. Jmeter3 using DBCP2 as connections pool instead of excalibur(which Jmeter2 use). Then I dig into the code in class PoolingDataSource which in DBCP2.. __________________________________CODE_________________________________ public Connection getConnection() throws SQLException { try { C conn = _pool.borrowObject(); if (conn == null) { return null; } return new PoolGuardConnectionWrapper<>(conn); } catch(SQLException e) { ___________________________________________________________________ As the above,the method "getConnection" will return new PoolGuardConnectionWrapper<>(conn) which could generate different hashcode for the conn returned. So the key "connection" will not exist in the perConnCache. then it will put the "new conn" into the perConnCache,which cause memory leak. Looking the method "getPreparedStatement" in class AbstractJDBCTestElement.(attached bug2).
The cache has been removed in JMeter 3.1: https://bz.apache.org/bugzilla/show_bug.cgi?id=60085
*** This bug has been marked as a duplicate of bug 60085 ***