-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Professional advice needed on connection consumption mystery
PostPosted: Mon Jul 08, 2013 12:11 am 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Dear All,

I'm troubleshooting an issue of a function which shoots up the database connection usage. The function is to update values for a number of sales records, to be done in a transaction for a batch of multiple records at one go. There could be 200 or 300+ records to be updated within the transaction, to be triggered by a command/action from UI.

We thought only one database connection is needed for each user/sessino running this function. However, the no. of database connections used is equivalent to the no. of sales records to be updated. That means, when there are 300 sales records to be updated, at least 300 database connection is utilized. This abrupt consumption of connection resources is undesirable.

Question: can anyone advise me how to avoid this? Is it supposed to be the case (one record update requires one database connection resource.)? I don't think so. There must be some statements or hiberate configurations hint you guys can lead me to the right direction. Thanks in advance!

We set up JNDI at weblogic server for the database connections. Below is the code segment for your advice:



public List<TransRec> updSalesRecList(List<TransRec> TransRecList,String auditUsername){

Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Transaction tx = null;
Iterator<TransRec> iterator = TransRecList.iterator();
SalesRec salesrec=null;
int i=0;
int count=0;

try{
tx = session.beginTransaction();
tx.setTimeout(180);
while(iterator.hasNext()){
salesrec=new SalesRec();
iterator.next();
salesrec=(SalesRec)session.get(SalesRec.class, TransRecList.get(i).getSalesRecId());
salesrec.setIsChecked(1L);
// setting other values....

if ( ++count % 20 == 0 ) {
//flush a batch of updates and release memory:
session.flush();
session.clear();
}

i++;
}
session.flush();
tx.commit();

}
catch(Exception e){
if (tx != null) {
tx.rollback();
}
errLogger.error("checkSalesRecList Transaction rollback - " + e, e);

}
finally{
if (session != null && session.isOpen()) {
session.close();
session = null;
}
auditor.info("checkSalesRecList:" + TransRecList + " completed.");
//return succeeded;
}
return TransRecList;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.