Re: OutOFMemory Java heap exeception

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Dec 30 2005 - 12:53:13 EST

  • Next message: Andrus Adamchik: "Re: heap memory not released"

    In addition to what was suggested here, I recommend to take a look at
    DataPort Ant task (and underlying DataPort class that can be embedded
    in your application). It has some memory optimizations, but its main
    advantage for bulk copy tasks is that it never uses DataObjects,
    working at the data row level.

    DataPort has its limitations, but is still worse considering if you
    don't have any special data massaging logic during the transfer. It
    is a part of Cayenne 1.2 (see 1.2 User Guide for Ant task details)
    and was a part of cayenne-examples in 1.1:

    http://objectstyle.org/cayenne/examples/data-port/cdataport.html

    Andrus

    On Dec 23, 2005, at 12:25 PM, <emre.yilma..r.net>
    <emre.yilma..r.net> wrote:

    > Hi,
    >
    > I want to transfer database records from one db to another.
    > Transfer size nearly 5000 data and this each data has nearly 1000
    > relational
    > objects.
    > ---->I firstly try the Paged query like :
    >
    > public static List getPersonels(){
    > SelectQuery query = new SelectQuery(Personel.class);
    > query.setPageSize(10);
    > return context.performQuery(query);
    > }
    > this method run of the first nearly 900 count of personel class but
    > personel
    > object has 2000 rows.
    >
    > ------>Then I try the ResultIterator like :
    >
    > public SelectQuery getPersonels(){
    > SelectQuery query = new SelectQuery(Personel.class);
    > query.setFetchingDataRows(true);
    > query.setPageSize(10);
    > return query;
    > }
    >
    > used below class
    > public static void transferPersonels(){
    > SelectQuery oldDbItems = tr.com.htr.hgys.olddb.Personel.getPersonels
    > ();
    > ResultIterator it = null;
    > try {
    > it = tr.com.htr.hgys.olddb.Personel.context.performIteratedQuery
    > (oldDbItems);
    > while(it.hasNextRow()) {
    > Map row = it.nextDataRow();
    > tr.com.htr.hgys.olddb.Personel oldDbItem =
    > (tr.com.htr.hgys.olddb.Personel)
    > tr.com.htr.hgys.olddb.Personel.context.objectFromDataRow(
    > tr.com.htr.hgys.olddb.Personel.class,(DataRow)row,true);
    > tr.com.htr.hgys.newdb.CopyOfPersonel newDbItem =
    > (tr.com.htr.hgys.newdb.
    > CopyOfPersonel) context.createAndRegisterNewObject("Personel");
    > try{
    > PersonelIdentity newIdent = PersonelIdentity.transferPersonelIdentity
    > (oldDbItem);
    > Card card = Card.transferPersonelCard(oldDbItem);
    > tr.com.htr.hgys.olddb.Daire daire =
    > tr.com.htr.hgys.olddb.Daire.getDaire
    > (oldDbItem.getDaireId());
    > String deptName = null;
    > if(daire != null)
    > deptName = daire.getDaireName();
    > Department dept = Department.getDepartment(deptName);
    > tr.com.htr.hgys.olddb.Gorev görev =
    > tr.com.htr.hgys.olddb.Gorev.getGorev
    > (oldDbItem.getGorevId());
    > String jobName = null;
    > if(görev != null)
    > jobName = görev.getGorevName();
    > Job job = Job.getJob(jobName);
    > tr.com.htr.hgys.olddb.Bolum bolum =
    > tr.com.htr.hgys.olddb.Bolum.getBolum
    > (oldDbItem.getBolumId());
    > String sectionName = null;
    > if(bolum != null)
    > sectionName = bolum.getBolumName();
    > Section section = Section.getSection(sectionName);
    > tr.com.htr.hgys.olddb.Unvan unvan =
    > tr.com.htr.hgys.olddb.Unvan.getUnvan
    > (oldDbItem.getUnvanId());
    > String titleName = null;
    > if(unvan !=null)
    > titleName = unvan.getUnvanName();
    > Title title = Title.getTitle(titleName);
    > tr.com.htr.hgys.olddb.Groups group =
    > tr.com.htr.hgys.olddb.Groups.getGroups
    > (oldDbItem.getGroupId());
    > String groupName = null;
    > if(group != null)
    > groupName = group.getGroupName();
    > Vehicle vehicle = Vehicle.getVehicle(oldDbItem);
    > newDbItem.setAccessGroupName(groupName);
    > newDbItem.setAddress(oldDbItem.getAdres());
    > newDbItem.setAutoCardRel(null);
    > newDbItem.setCardRel(card);
    > newDbItem.setClassRel(null);
    > newDbItem.setDeleted(new Boolean(false));
    > newDbItem.setDepartmentRel(dept);
    > newDbItem.setHomePhone(oldDbItem.getTelEv());
    > newDbItem.setJobRel(job);
    > newDbItem.setTaxNo(oldDbItem.getVergino());
    > newDbItem.setPersonelIdentityRel(newIdent);
    > newDbItem.setPersonelImageRel(null);
    > newDbItem.setPersonList(null);
    > newDbItem.setRecordDate(oldDbItem.getDateofrec());
    > newDbItem.setRecordNo(oldDbItem.getSicilno());
    > newDbItem.setRoomNumber(oldDbItem.getOda());
    > newDbItem.setSectionRel(section);
    > newDbItem.setTitleRel(title);
    > newDbItem.setUnitRel(null);
    > newDbItem.setVehicleRel(vehicle);
    > newDbItem.setWirelessPhone(oldDbItem.getTelCep());
    > newDbItem.setWorkPhone(oldDbItem.getTelDahili());
    > context.commitChanges();
    >
    > }catch (Exception e){
    > e.printStackTrace();
    > }
    > java.lang.System.gc();
    > }
    > }
    > catch(CayenneException ex) {
    > ex.printStackTrace();
    > }
    > finally {
    > try {
    > it.close();
    > }catch(CayenneException closeEx) {
    > closeEx.printStackTrace();
    > }
    > }
    > context.commitChanges();
    > }
    >
    > this time I get an error of cayenne for connection timeout.
    > I guess this is caused by other querys in transferPersonels() metod.
    >
    > How can I solve the out of memory problem..
    >
    > Thanks for help...
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Dec 30 2005 - 12:53:22 EST