Re: Exception in thread "main" java.lang.OutOfMemoryError:

From: Roland Walter <rwa(at)mosaic-ag(dot)com>
To: Jim Davis <j(dot)a(dot)davis(at)larc(dot)nasa(dot)gov>
Subject: Re: Exception in thread "main" java.lang.OutOfMemoryError:
Date: 2006-08-25 14:15:00
Message-ID: rc44pw0rjff.fsf@mosaic-ag.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I tried to verify, if i would see any memory increase, when running the
following program on a table with about 6.6 million rows.

I used java 1.4.2_05, java 1.5.0_07, jdbc3 driver builds number 407
and 503. The database was a 7.4.13 on a Linux-box, the java program
was executed on win-2k.

There was no increase of memory requirements. The java process always
used about 10 Megabytes, running for about 1.5 minutes. The statement
had no ResultSet.

A defining sql statement does not return a ResultSet, so I do not understand
why your process died due to exhausted memory.

BTW setting a cursor name
or use of setFetchSize or not, did not change anything.

import java.lang.ClassNotFoundException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;

/**
* Drops and creates an index on the billing transaction table.
* In pgsql-jdbc has been a report of an OutOfMemoryException when
* creating an index on a table with 27 million rows.
*/
class DropCreateIndex {
static String user = "billtest";
static String password = "billtest";
static String url = "jdbc:postgresql://aupc306:5432/billtst1";
static String driverClassName = "org.postgresql.Driver";
static String dropIndex = "DROP INDEX xitransaction3";
static String createIndex = "CREATE INDEX xitransaction3 on transaction using btree (cc_trans_id, bc_id)";

public static void main(String[] args) {
Connection con = null;
Statement st = null;

try {
Class.forName(driverClassName);
} catch (ClassNotFoundException e) {
System.out.println("Driver " + driverClassName + " is not in the CLASSPATH!");
System.exit(1);
}

try {
con = DriverManager.getConnection(url, user, password);

con.setAutoCommit(false);

st = con.createStatement();

st.setFetchSize(100);
st.setCursorName("drop_cursor");

boolean hasResultSet = st.execute(dropIndex);

if (hasResultSet) {
System.out.println("Statement \"" + dropIndex + "\" has a ResultSet");
}

System.out.println("Dropped index!");

st.setCursorName("create cursor");
hasResultSet = st.execute(createIndex);

if (hasResultSet) {
System.out.println("Statement \"" + createIndex + "\" has a ResultSet");
}

System.out.println("Created index!");

con.commit();

} catch (SQLException e) {
System.err.println("ERROR: " + e.getMessage());
e.printStackTrace();

if (con != null) {
try {
con.rollback();
} catch (SQLException e2) {
System.err.println("Rollback failed! " + e.getMessage());
}
}
} finally {
if (st != null) {
try {
st.close();
} catch (SQLException e1) {
// do nothing
}
}

if (con != null) {
try {
con.close();
} catch (SQLException e1) {
// do nothing
}
}
}
}

}

--
Roland Walter mailto: rwa (at) mosaic-ag (dot) com
MOSAIC SOFTWARE AG phone: +49 (0) 22 25 / 88 2-44 9
Am Pannacker 3 fax: +49 (0) 22 25 / 88 2-20 1
D-53340 Meckenheim http://www.mosaic-ag.com

Die in dieser E-Mail enthaltenen Nachrichten und Anhaenge sind ausschliesslich
fuer den bezeichneten Adressaten bestimmt. Sie koennen rechtlich geschuetzte,
vertrauliche Informationen enthalten. Falls Sie nicht der bezeichnete Empfaenger
oder zum Empfang dieser E-Mail nicht berechtigt sind, ist die Verwendung,
Vervielfaeltigung oder Weitergabe von Nachrichten und Anhaengen untersagt.
Falls Sie diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte
unverzueglich den Absender und vernichten Sie die E-Mail.

This e-mail message and any attachment are intended exclusively for the named
addressee. They may contain confidential information which may also be protected
by professional secrecy. Unless you are the named addressee (or authorised to
receive for the addressee) you may not copy or use this message or any attachment
or disclose the contents to anyone else. If this e-mail was sent to you by mistake
please notify the sender immediately and delete this e-mail.

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2006-08-25 18:00:57 Re: Exception in thread "main" java.lang.OutOfMemoryError:
Previous Message Joe Audette 2006-08-25 12:21:00 Re: [ADMIN] CMS - portal server Question