Hi Peter, It is really hard to tell exactly what the problem with your code is, because it is not a complete one, but in case of OOM some "irrelevant" details may be a culprit. Nevertheless, it looks like "data" is some sort of a queue, continuously populated by another thread, or just a big chunk of preropulated data? In both cases your condition for batch commit (data.size() % 100000 == 0 || data.size() < 100000) looks suspicious. Let's assume prepopulated data of size 100000 * 12345 +1 You may end up committing batch of size 1.2 billion+, wchich would totally explain OOM..
On Tuesday, November 21, 2023 at 5:41:30 AM UTC-5 mche...@gmail.com wrote: > Dear All > I keep clicking the data to h2 by stmt.addBatch(), after i called > executeBatch, memory is not free, so finally out of memory, may i know why > please? > > > @Override > public void run() { > while (!stopped) { > synchronized (sharedLock) { > try { > // System.out.println("data.size() =" + data.size()); > for (int z = 0; z < data.size() && z < 100000; z++) { > Object[] temp; > synchronized (data) { > temp = data.pollLast(); > } > int x = 1; > stmt.setLong(x++, (Long) temp[0]); > stmt.setString(x++, (String) temp[1]); > stmt.setString(x++, (String) temp[2]); > stmt.setString(x++, (String) temp[3]); > stmt.setInt(x++, (int) temp[4]); > for (int tempX = 0; tempX < registers.size(); tempX++) { > stmt.setLong(x, ((BigInteger) temp[x - 1]).longValue()); > x++; > } > stmt.addBatch(); > } > if (data.size() % 100000 == 0 || data.size() < 100000) { > stmt.executeBatch(); > conn.commit(); > } > } catch (SQLException ex) { > Logger.getLogger(H2Thread.class.getName()).log(Level.SEVERE, null, ex); > } > } > try { > Thread.sleep(500); > } catch (InterruptedException ex) { > Logger.getLogger(H2Thread.class.getName()).log(Level.SEVERE, null, ex); > } > } > } > > thanks > Peter (mche...@hotmail.com) > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/0c138c38-ba35-4543-a4e3-45e9cbc4ccf8n%40googlegroups.com.