jvm - How to resolve java.lang.OutOfMemoryError: Java heap space without increasing the heap memory size -


i know there lot of questions on java.lang.outofmemoryerror: java heap space.

like question 1

but none of links not proper answers question.

we generating reports in spreadsheet format, huge data coming database side. increased heap memory size 2 gb 4 gb, no use.

may because of space in database column, trimmed getters , setters using trim() method, no use.

for example :

string s = "hai       "; s.trim(); 

if 1 having how resolve issue java coding side, without increasing size of heap space. because client told, not increase heap space more.

when calling method getting exception

private crosstabresult mergealllistssamendc(crosstabresult crt, crosstabresult res) {          crt.setformularytier(crt.getformularytier()==null ? "":((crt.getformularytier().contains(crt.getlistid())? crt.getformularytier(): crt.getlistid()+crt.getformularytier()) +"~"+res.getlistid()+res.getformularytier()));         crt.setformularytierdesc(crt.getformularytierdesc()==null ? "":((crt.getformularytierdesc().contains(crt.getlistid())? crt.getformularytierdesc(): crt.getlistid()+crt.getformularytierdesc()) +"~"+res.getlistid()+res.getformularytierdesc()));} 

can't share more code, due confidential. looking above code, if people have alternative solution means inform me. merging 2 string based on same id.

we generating reports in spreadsheet format, huge data coming database side.

in kind of use cases, have @ least 2 things study may improve consumed memory first have identify culprits.

mainly causes identified monitoring tools in use case :

1) if data loaded db identified big consumer of memory, should not load data in 1 shot.
keeping theses objects in memory , in same time creating spreadsheet these data may consume lot of memory.
overall if application parallely used other use cases. should rather divide retrieval in several retrievals.
invoke 1 retrieve objects, populate spreadsheat , free these objects not required longer. , on...

2) during spreadsheet creation, if object spreadsheet created library identified big consumer of memory, should favor streaming api or event api write spreadsheet on api loads whole spreadsheet in memory.
example poi provides dom-like api : xssf , streaming api : sxssf.
don't specify library use create spreadsheet doesn't matter logic use should same anyone.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -