newbie random outofmemory exceptions

Discussion in 'Java' started by Mark, Oct 21, 2008.

  1. Mark

    Mark Guest

    i haven't touched java since university and most of my current job is taken up
    with writing custom persistence frameworks for data entry applications in c++,
    so after discovering jpa (which looks like a godsend) i wrote a really simple
    program to test it out (see below).

    using netbeans i generated the jpa entities (24 in total), edited them to remove
    incorrect @Id annotations, setters for primary keys, and recursive relations
    except in the case of a parent-child relationship.

    the problem is that after running for about 5 minutes i get "Exception in thread
    "main" java.lang.OutOfMemoryError: Java heap space" in random places. i
    increased the minimum heap size to 128mb and maximum to 256mb from their
    defaults which had no effect. the little memory indicator in netbeans that
    displays when debugging doesn't go over 60mb (out of 80mb in total). jprobe
    shows out of 80mb memory usage the JVM takes about 50mb and the test program
    only takes 30mb.

    is there something i'm doing wrong? or something i can do to tell what's taking
    up all the heap space?

    TIA

    public void test() {

    try {
    EntityManager em = emf.createEntityManager();
    Connection con = DriverManager.getConnection("connection string");
    Statement st = con.createStatement();
    Query q = em.createQuery("select p from Product p" +
    " where p.productid = :productid");
    ResultSet rs = st.executeQuery("select productid from product order
    by productid");

    while (rs.next()) {
    int productid = rs.getInt("PRODUCTID");
    q.setParameter("productid", productid);
    Product p = (Product)q.getSingleResult();
    }

    st.close();
    con.close();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }
     
    Mark, Oct 21, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LP

    System.OutOfMemory Exception

    LP, Jan 21, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    12,215
    Tad Marshall
    Apr 9, 2005
  2. vMike

    system.outofmemory exception

    vMike, Oct 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,154
    vMike
    Oct 30, 2003
  3. globalrev
    Replies:
    4
    Views:
    823
    Gabriel Genellina
    Apr 20, 2008
  4. Navin Mishra
    Replies:
    0
    Views:
    294
    Navin Mishra
    Mar 5, 2007
  5. VK
    Replies:
    15
    Views:
    1,335
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page