davidmoten / rxjava3-jdbc

Apache License 2.0
8 stars 1 forks source link

Getting out of memory Issues #67

Open Jojanyu15 opened 10 months ago

Jojanyu15 commented 10 months ago

Hi, I'm getting some issues when I try to fetch more than one million of rows. I'm Using Spring 3.1.2 Java 17 with webflux. The code that I'm using to fetch a page is the following:

` return RxJava3Adapter.flowableToFlux(database .select(queryString) .fetchSize(10000) .get(resultSet -> {

                ResultSetMetaData metaData = resultSet.getMetaData();

                int columnCount = metaData.getColumnCount();

                return Flux.<Map<String, Object>>create(emitter -> {

                    try {
                        while (resultSet.next()) {
                            Map<String, Object> row = new HashMap<>();
                            for (int i = 1; i <= columnCount; i++) {
                                String columnName = metaData.getColumnName(i);
                                Object columnValue = resultSet.getObject(i);
                                row.put(columnName, columnValue);
                            }
                            emitter.next(row);
                        }
                        emitter.complete();
                    } catch (SQLException sqlException) {
                        emitter.error(sqlException);
                    }
                });
            })).flatMap(flux -> flux);`

I'm trying to figure what's wrong and why is getting this out of memory exception. The exception that is throwing is Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "RxCachedWorkerPoolEvictor-1"

davidmoten commented 10 months ago

This is really an anti-pattern for rxjava3-jdbc use. The get method is designed to map one row only to a value (an object of your choice which looks to be a Map<String, Object>). I can provide more details tomorrow if needed.

Jojanyu15 commented 9 months ago

This is really an anti-pattern for rxjava3-jdbc use. The get method is designed to map one row only to a value (an object of your choice which looks to be a Map<String, Object>). I can provide more details tomorrow if needed.

Yes it will help me a lot. Thank you so much in advance.