Exceeding GCOverhead Limit

The following code throws an OutofMemoryError on a Linux Enterprise Enterprise running jdk1.6.0_14, but works fine on JDK 1.6.0_20. I do not know why this is happening.

while (rs.next()) {
  for (TableMetaData tabMeta : metaList) {
rec.append(getFormattedString(rs, tabMeta));
  }
  rec.append(lf);
  recCount++;
  if (recCount % maxRecBeforWrite == 0) {
    bOutStream.write(rec.toString().getBytes());
    rec = null;
    rec = new StringBuilder();
  }
}
bOutStream.write(rec.toString().getBytes());

The getFormattedString () method is used here:

private String getFormattedString(ResultSet rs, TableMetaData tabMeta)
        throws SQLException, IOException {

    String colValue = null;
    // check if it is a CLOB column
    if (tabMeta.isCLOB()) {
        // Column is a CLOB, so fetch it and retrieve first clobLimit chars.
        colValue = String.format("%-" + clobLimit + "s", getCLOBString(rs,
                tabMeta));
    } else {
        colValue = String.format("%-" + tabMeta.getColumnSize() + "s", rs
                .getString(tabMeta.getColumnName()));
    }
    return colValue;
}

The following is the exception trace:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
        at java.util.Formatter$FormatSpecifier.justify(Formatter.java:2827)
        at java.util.Formatter$FormatSpecifier.print(Formatter.java:2821)
        at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2794)
        at java.util.Formatter$FormatSpecifier.print(Formatter.java:2677)
        at java.util.Formatter.format(Formatter.java:2433)
        at java.util.Formatter.format(Formatter.java:2367)
        at java.lang.String.format(String.java:2769)
        at com.boa.cpal.cpal2repnet.main.CPALToReportNet.getFormattedString(Unknown Source)

I suspect that using String.format is the culprit, but not sure. How to overcome this problem?

Note that this code was written to query a database with huge tables to read a result set and create extract files with specific formatting.

+3
source share
2 answers

, , GC, HotSpot:

-XX: + UseGCOverheadLimit - , VM, GC, , OutOfMemory. ( 6.)

, , . @Andreas_D , jdk1.6.0_14 JDK 1.6.0_20, . :

  • JVM. ( UPDATE - 2012/06, JDK 1.6.0_20 . 1.6 1.7 .)

  • -Xmx -Xms JVM. ( JVM), , .

GC, , , .

, , , .

+2

JDK 1.6.0_18:

JVM Java . , , , .

, 1.6.0_20.


:

// Column is a CLOB, so fetch it and retrieve first clobLimit chars.
colValue = String.format("%-" + clobLimit + "s", getCLOBString(rs, tabMeta));

colValue clobLimit CLOB, clobLimit.

 System.out.println(String.format("%-5s", "1234567890"));

 1234567890

, , :

colValue = getCLOBString(rs, tabMeta).substring(0, clobLimit);
0

Source: https://habr.com/ru/post/1761241/


All Articles