现在有一个批量存储的代码 DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
gpsConnection = DriverManager.getConnection("地址", "用户名","密码");
gpsPS = (PreparedStatement) gpsConnection.prepareStatement(gpsSQL);
gpsConnection.setAutoCommit(false);,因为是批量存储,所以gpsPS 和gpsConnection 始终没关闭,等到下一轮存储的时候,还执行上面的连接代码,应该是把gpsPS 和gpsConnection覆盖了吧,那前一轮的gpsPS 和gpsConnection会释放吗?现在压力是存储2000条没问题,4000条内存蹭蹭往上涨,是这个原因吗?
gpsConnection = DriverManager.getConnection("地址", "用户名","密码");
gpsPS = (PreparedStatement) gpsConnection.prepareStatement(gpsSQL);
gpsConnection.setAutoCommit(false);,因为是批量存储,所以gpsPS 和gpsConnection 始终没关闭,等到下一轮存储的时候,还执行上面的连接代码,应该是把gpsPS 和gpsConnection覆盖了吧,那前一轮的gpsPS 和gpsConnection会释放吗?现在压力是存储2000条没问题,4000条内存蹭蹭往上涨,是这个原因吗?
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
gpsConnection = DriverManager.getConnection("地址", "用户名","密码");
gpsPS = (PreparedStatement) gpsConnection.prepareStatement(gpsSQL);
gpsConnection.setAutoCommit(false);
while(true) {
Thread.sleep(1);
for(...)
{
gpsPS.addBatch();
}
gpsPS.executeBatch();
gpsConnection.commit();
}
相当于每1毫秒钟执行一次批量存储,也有commit之类的,始终执行,while(true),所以始终不需要关闭操作。这样有问题吗?
gpsConnection.clearWarnings();
Warnings内存泄露是一个已知问题。暂不清楚长时间不释放连接是否还有其它泄漏风险。