View Single Post
  #1 (permalink)  
Old 08-29-2008, 04:11 PM
mathes_n mathes_n is offline
Member
 
Join Date: Aug 2008
Posts: 4
mathes_n is on a distinguished road
Performance issue
Hi,


The piece of code marked bold iterate 2000 times due the result set in table and as result the CPU utilization is hitting 100% for a 2 GB RAM Server with 4 GHZ processor.


public List retrieveCustomersForSearch() throws Exception{
List customers = null;
Session session = null;
CustomerBean customerBean = null;
Object[] resultArray = null;
try {
session = HibernateUtil.currentSession();
String SQLQuery = "SELECT name,customer_id FROM CUSTOMERS order by name";
List tempList = session.createSQLQuery(SQLQuery)
.addScalar("customer_id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.list();
tempList = tempList==null?new ArrayList():tempList;
customers = new ArrayList();
for (int index = 0; tempList!=null && index < tempList.size(); index++) {
resultArray = (Object[]) tempList.get(index);
customerBean = new CustomerBean();
customerBean.setCustomerId(Long.valueOf(resultArra y[0].toString()));
if(resultArray[1]!= null) {
customerBean.setName(resultArray[1].toString());
}else {
customerBean.setName(null);
}

customers.add(customerBean);
}


} catch (HibernateException he) {
log.error("caught: " + he);
throw new PersistenceException(he.getMessage(), he);
} catch (Exception e) {
e.getMessage();
throw new RuntimeException("Unable to retrive Customers from datastore: ", e);
}
return customers;
}

Is there some other way of implementation so that i can solve the issue

Please help me out

Thanks in Advance!
Reply With Quote
Sponsored Links