Web application uses one Entity Bean (ejb 2.0) and has one page to output objects from database. I implements all methods in entity been and checked all errors. I have a table in database and try to output first 100 objects (id's and their names). But It takes 20 seconds for hundred objects, it' unreal slow:( Tried several implementations of Entity Bean, results are the same.
private void loadRow() throws SQLException, NamingException, Exception {
try {
String selectStatement =
"select parent_id, object_type_id, object_class_id, project_id, picture_id, name, description, attr_schema_id, order_number, source_object_id, version\n"+
"from nc_objects where object_id = ?";
Map results = (Map) JDBCExecutor.execute(selectStatement, Arrays.asList(new Object[]{new BigDecimal(objectId)}), new ResultSetHandler() {
public Object onResultSet(ResultSet rs) throws Exception {
Map results = new HashMap();
if (rs.next()) {
results.put("parent_id", checkedValue(rs, 1));
results.put("object_type_id", checkedValue(rs, 2));
results.put("object_class_id", checkedValue(rs, 3));
results.put("project_id", checkedValue(rs, 4));
results.put("picture_id", checkedValue(rs, 5));
results.put("name", rs.getString(6));
results.put("description", rs.getString(7));
results.put("attr_schema_id", checkedValue(rs, 8));
results.put("order_number", checkedValue(rs, 9));
results.put("source_object_id", checkedValue(rs, 10));
results.put("version", checkedValue(rs, 11));
}
return results;
}
});
this.parentId = (BigInteger) results.get("parent_id");
this.objectTypeId = (BigInteger) results.get("object_type_id");
this.objectClassId = (BigInteger) results.get("object_class_id");
this.projectId = (BigInteger) results.get("project_id");
this.pictureId = (BigInteger) results.get("picture_id");
this.name = (String) results.get("name");
this.description = (String) results.get("description");
this.attrSchemaId = (BigInteger) results.get("attr_schema_id");
this.orderNumber = (BigInteger) results.get("order_number");
this.sourceObjectId = (BigInteger) results.get("source_object_id");
this.version = (BigInteger) results.get("version");
}
catch(Exception ex){
throw new Exception("My EXCEPTION; cannot load object_id = " + objectId, ex);
}
String selectStatement = "select object_id, attr_id, value, date_value, list_value_id, data "
+ " from nc_params\n"
+ "where object_id = ?";
params = (Map) JDBCExecutor.execute(selectStatement, Arrays.asList(new Object[]{new BigDecimal(objectId)}), new ResultSetHandler() {
public Object onResultSet(ResultSet rs) throws Exception {
Map results = new HashMap();
while(rs.next()){
if(rs.getString(3) != null)
results.put(checkedValue(rs, "attr_id"), rs.getString(3));
}
return results;
}
});
}
This is my loadRow method, that is called from ejbLoad. I'm not sure, but maybe trouble is there?
Does your EJB method return 100 objects as a list, or do you make 100 calls, one per row?
EJB method calls are expensive. Try packing as much data as possible in one round-trip.
Try timing (better yet, profiling) the code inside the EJB calls. Are you positive that the JDBC calls are lightning-fast?
(I'm not asking what makes you in 2012 use EJB instead of saner and lighter architectures; I hope it's just a legacy system.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.