我在循环中使用PreparedStatement executeQuery并获得如下的OOM,
java.lang.OutOfMemoryError: GC overhead limit exceeded
com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:2267)
com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:2044)
com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3549)
com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:489)
com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3240)
com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2411)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2834)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
每个查询可能会查询大约100条记录,当循环到达第7或第8时,错误就会消失。
代码
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/ma30");
Connection conn = ds.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet res = pstmt.executeQuery();
有人有想法吗?