当前位置:   article > 正文

MySQL结果集Java_java – 使用MySQL传输大型结果集

java出现大结果集的场景

我正在开发一个使用大型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) line: not available [native method]

SocketInputStream.read(byte[], int, int) line: 129

ReadAheadInputStream.fill(int) line: 113

ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(byte[], int, int) line: 160

ReadAheadInputStream.read(byte[], int, int) line: 188

MysqlIO.readFully(InputStream, byte[], int, int) line: 2428

MysqlIO.reuseAndReadPacket(Buffer, int) line: 2882

MysqlIO.reuseAndReadPacket(Buffer) line: 2871

MysqlIO.checkErrorPacket(int) line: 3414

MysqlIO.checkErrorPacket() line: 910

MysqlIO.nextRow(Field[], int, boolean, int, boolean, boolean, boolean, Buffer) line: 1405

RowDataDynamic.nextRecord() line: 413

RowDataDynamic.next() line: 392

RowDataDynamic.close() line: 170

JDBC4ResultSet(ResultSetImpl).realClose(boolean) line: 7473

JDBC4ResultSet(ResultSetImpl).close() line: 881

DelegatingResultSet.close() line: 152

DelegatingResultSet.close() line: 152

DelegatingPreparedStatement(DelegatingStatement).close() line: 163

(This is my class) Database.close() line: 84

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/422367
推荐阅读
相关标签
  

闽ICP备14008679号