0

I have Postgres DB, 7500 rows in Client table, -Xmx8m.

 Query query = session.createQuery("select c from Client c");
ScrollableResults resultSet = query.setFetchSize(50).setCacheMode(CacheMode.IGNORE)
.scroll(ScrollMode.FORWARD_ONLY);
    int i = 0;

    while (resultSet.next()) {
        Client client = (Client) resultSet.get(0);
        System.out.println(client.getId());
        i++;
        if (i % 50 == 0) {
            session.clear();
            Thread.sleep(500);
        }
    }
    session.clear();
    resultSet.close();

When I run my app I got this : .... 4188 java.lang.OutOfMemoryError: GC overhead limit exceeded

Then I have set -Xmx1024m and run jvisualvm and got this -

enter image description here Why I got a lot of strings ???? Who can explain why OutOfMemory is occurred ?

idmitriev
  • 4,619
  • 4
  • 28
  • 44

1 Answers1

-2

Since its a stateful session. Objects are not evicted. In addition to session.clear() do call session.flush(). Since its stateful session all objects will be in memory due to hibernate first level cache.

Otherwise use stateless session

https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html

Ahmad
  • 12,336
  • 6
  • 48
  • 88
user3435860
  • 59
  • 1
  • 5