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!