6 messages in com.mysql.lists.javaRE: java.lang.OutOfMemoryError -- mem...
FromSent OnAttachments
Vinicios Torres02 Apr 2001 12:14 
Vinicios Torres02 Apr 2001 12:50 
Filip Hanik02 Apr 2001 12:54 
Vinicios Torres02 Apr 2001 13:08 
Tim Endres02 Apr 2001 13:10 
Filip Hanik02 Apr 2001 13:13 
Subject:RE: java.lang.OutOfMemoryError -- memory leak in JDBC or servlet engine??
From:Filip Hanik (ma@filip.net)
Date:04/02/2001 01:13:47 PM
List:com.mysql.lists.java

Why I can't share the Connection object?

you can share it fine, it is however, what do you do when you share it! that is your problem, not the query itself.

if you are running out of memory because you are sharing connection objects, means that resources don't get cleaned up somewhere, check your code for these traps

Filip

-----Original Message----- From: Vinicios Torres [mailto:vtor@netpar.com.br] Sent: Monday, April 02, 2001 1:09 PM To: Filip Hanik; resi@caucho.com; ja@lists.mysql.com Subject: Re: java.lang.OutOfMemoryError -- memory leak in JDBC or servlet engine??

Good sugestion! However, the table has only eight cols, all numbers, and in pratice the ResultSet has no more than 10 rows. I hopped all objects elegible to GC after method ends.

But I have a new fact: when I put the creation of Connection object inside the method and don't pass as parameter, all runs smoothly.

Why I can't share the Connection object?

why do you do a

"select a.* " instead of "select a.nr_prestacao from ..."

if you only use one column? while(rs.next()) {

nmsg++; msg += rs.getInt("nr_prestacao") + " "; }

you are retrieving a lot more data than necessary

Filip

~ Namaste - I bow to the divine in you ~ Filip Hanik Software Architect fil@filip.net www.filip.net

-----Original Message----- From: Vinicios Torres [mailto:vtor@netpar.com.br] Sent: Monday, April 02, 2001 12:51 PM To: Filip Hanik; ja@lists.mysql.com Subject: Re: java.lang.OutOfMemoryError -- memory leak in JDBC or servlet engine??

Hi, Filip,

use the heap flag with java to extend your memory., java -mx32M .....

I use -Xmx48M. But I dont understand why this occurs in simple method.

also make sure you clean up your resources (unreference them)

I did this using the finally block...

if you still have problems finding your memory leaks, take a look at a tool called JProbe that will help you track down memory.

Thanks to this sugestion.

Filip

private StringBuffer omsg = new StringBuffer(1024);;

private StringBuffer getMsgAtrasada() { return omsg; } private boolean isContratoAtrasado(Connection conn, int nr_contrato) { int nrContrato = 0; String msg = null; omsg.setLength(0);

// Verifica se tem prestacao atrasada sem acerto PreparedStatement pStmt = null; ResultSet rs = null; try { pStmt = conn.prepareStatement( "SELECT a.* " + " FROM lote_prestacao a " + " LEFT JOIN lote_prestacao_adiada b " + " ON (a.nr_contrato = b.nr_contrato AND a.nr_prestacao = b.nr_prestacao) " + " WHERE a.dt_vencimento < NOW() " + " AND a.dt_pagamento IS NULL " + " AND b.nr_contrato IS NULL " + " AND a.nr_contrato = ? " ); pStmt.setInt( 1, nr_contrato); rs = pStmt.executeQuery();

// Monta mensagem que tem prestacoes atrasadas int nmsg = 0; msg = "Até " + Util.fmtData(new java.util.Date()) + " não constava pagto prest: "; while(rs.next()) { nmsg++; msg += rs.getInt("nr_prestacao") + " "; }

// Se prestacao tiver mais de 3, não gera boleto if (nmsg > 0) { omsg.append(msg); if (nmsg > 3) return true; // esta atrasado } } catch (Exception e) { e.printStackTrace(); } finally { System.out.println("Liberando verific. prest. atrasada"); JdbcUtil.close(rs, true); JdbcUtil.close(pStmt, true); rs = null; pStmt = null; msg = null; }

return false; // nao esta' atrasado }

---------------------------------------------------------------------

Please check

"http://www.mysql.com/Manual_chapter/manual_toc.html" before

posting. To request this thread, e-mail java@lists.mysql.com

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.