我正在开发一个使用大型MySQL表的spring应用程序。加载大表时,我得到一个OutOfMemoryException,因为驱动程序试图将整个表加载到应用程序内存中。
我尝试使用
statement.setFetchSize(Integer.MIN_VALUE);
但是然后我打开的每个ResultSet都挂了close(); 在网上查找时,我发现发生这种情况是因为它尝试在关闭ResultSet之前尝试加载所有未读的行,但事实并非如此,因为我这样做是:
ResultSet existingRecords = getTableData(tablename);
try {
while (existingRecords.next()) {
// ...
}
} finally {
existingRecords.close(); // this line is hanging, and there was no exception in the try clause
}
小表(3行)也会发生挂起,如果我不关闭RecordSet(在一种方法中发生),则会connection.close()挂起。
挂起的堆栈跟踪:
SocketInputStream.socketRead0(FileDescriptor,byte [],int,int,int)行:不可用[本机方法]
SocketInputStream.read(byte [],int,int)行:129
ReadAheadInputStream.fill(int)行:113
ReadAheadInputStream。 readFromUnderlyingStreamIfNecessary(byte [],int,int)行:160
ReadAheadInputStream.read(byte [],int,int)行:188
MysqlIO.readFully(InputStream,byte [],int,int)行:2428 MysqlIO.reuseAndReadPacket(Buffer ,int)行:2882
MysqlIO.reuseAndReadPacket(Buffer)行:2871
MysqlIO.checkErrorPacket(int)行:3414
MysqlIO.checkErrorPacket()行:910
MysqlIO.nextRow(Field [],int,boolean,int,boolean,boolean,布尔值,缓冲区)行:1405
RowDataDynamic.nextRecord()行:413
RowDataDynamic.next()行:392 RowDataDynamic.close()行:170
JDBC4ResultSet(ResultSetImpl).realClose(boolean)行:7473 JDBC4ResultSet(ResultSetImpl).close()行:881 DelegatingResultSet.close ()行:152
DelegatingResultSet.close()行:152
DelegatingPreparedStatement(DelegatingStatement).close()行:163
(这是我的课程)Database.close()行:84
qq_花开花谢_0
智慧大石