相关疑难解决方法(0)

使用MySQL流式传输大型结果集

我正在开发一个使用大型MySQL表的spring应用程序.当加载大表时,我得到一个OutOfMemoryException,因为驱动程序试图将整个表加载到应用程序内存中.

我试过用

statement.setFetchSize(Integer.MIN_VALUE);
Run Code Online (Sandbox Code Playgroud)

但是我打开的每个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
}
Run Code Online (Sandbox Code Playgroud)

挂起也发生在小表(3行)上,如果我不关闭RecordSet(发生在一个方法中)然后connection.close()挂起.


堆栈跟踪挂起:

SocketInputStream.socketRead0(FileDescriptor,byte [],int,int,int)行:不可用[native method]
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, boolean,Buffer)行:1405
RowDataDynamic.nextRecord()行:413
RowDataDynamic.next()行:392 RowDataDynamic.close()行:170
JDBC4ResultSet(ResultSetImpl).realClose(boolean)行:7473 JDBC4ResultSet(ResultSetImpl).close( )line:881 DelegatingResultSet.close()行:152
DelegatingResultSet.close()行:152
DelegatingPreparedStatement(DelegatingStatement).clo se()行:163
(这是我的类)Database.close()行:84

java mysql streaming spring

44
推荐指数
2
解决办法
5万
查看次数

标签 统计

java ×1

mysql ×1

spring ×1

streaming ×1