我正在开发一个使用大型MySQL表的spring应用程序.加载大表时,我得到OutOfMemoryException
,因为驱动程序试图将整个表加载到应用程序内存中.
我试着用
statement.setFetchSize(Integer.MIN_VALUE);
但我打开的每个结果集都会挂起close()
;在网上查看时,我发现这是因为它在关闭结果集之前try 加载任何未读行,但事实并非如此,因为我这样做:
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行)上,如果我不关闭记录集(在一个方法中发生),那么connection.close()
次挂起.
挂起的堆栈跟踪:
SocketInputStream.socketRead0(文件描述符,字节[],int,int,int)行:不可用[本机方法]