• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Java Heap space error while adding database resultset to Hashmap  RSS feed

 
Tinu Sugathan Mohana
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting Java Heap space error while adding database resultset to Hashmap, below is the method i am using in my application, kindly suggest how can i resolve this issue

private HashMap<String, String> loadOrganiztionMapping(Connection smDbConn) {

Statement stmnt = null;
HashMap<String,String> map = null;
try{
map = new HashMap<String,String>();
stmnt = smDbConn.createStatement();
ResultSet rs1 = stmnt.executeQuery("SELECT org_id, org_code FROM bms_organization");
while(rs1.next()){
map.put(rs1.getString("org_code"), rs1.getString("org_id"));
}
rs1.close();
}
catch(Exception e){
log.error(MobilyException.getStackTraceAsString(e));
}
finally {
if(stmnt != null){
try {
stmnt.close();
} catch (SQLException e) {
log.error(MobilyException.getStackTraceAsString(e));
}
}
}
return map;
}




javaerror.JPG
[Thumbnail for javaerror.JPG]
Error sceernshot
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code can you please wrap it in code tags (there's a button on the editor page) so it retains its formatting.

How many rows are there in the table?

Does it always crash here?
Does it do that every time it enters this method, or is it only after the system has been running for some time?

What happens to the Map after it exits this method?
Is this method in a loop somewhere?
Or maybe at the end of a chain of calls that builds up a large data set?

These are the sorts of things you need to look at.

That and taking a memory dump and analysing it using something like jhat or some other analysis tool to see if you can spot what class is filling up the heap (other than String).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!