jsf - java.lang.OutOfMemoryError: Java heap space - how to save memory? -



jsf - java.lang.OutOfMemoryError: Java heap space - how to save memory? -

i'm trying tune jsf application memory consuption setting jvm arguments because i'm getting out of memory error.

i'm able increment memory heap , restart server twice day, it's not solution...

jvm arguments:

-xx:+useconcmarksweepgc -xx:+useparnewgc -xx:+cmsclassunloadingenabled -xx:+cmsparallelremarkenabled -xx:cmsinitiatingoccupancyfraction=30 -xx:+cmsincrementalmode -xx:+cmsincrementalpacing -xx:parallelcmsthreads=2 -xx:+usecmscompactatfullcollection -xx:+disableexplicitgc -xx:maxheapfreeratio=70 -xx:minheapfreeratio=40 -xx:maxtenuringthreshold=30 -xx:newsize=512m -xx:maxnewsize=512m -xx:survivorratio=2 -xx:permsize=150m -xms1024m -xmx1024m

everything seems work fine, tenured space @ 0 mb, eden space continuosly cleared survivor space still growing , when reach limit, object moved tenured space , never been released. , after half day of running application out of memory error. have schedule automatical restarts of tomcat server.

so think, there must problem in application, because memory consuption high such little appl (about thousands movements in database per day).

there part of code:

bean.java

/* save datalist */ public void save() { session = daosf.getsessionfactory.opensession(); seek { dao.save(datalist); } grab (exception e) {...} { session.close(); } }

dao.java

public static void save(list<? extends object> datalist) { (object dataitem : datalist) { save(dataitem); } } public static void save(object dataitem) { seek { transaction tx = session.begintransaction(); session.save(dataitem); tx.commit(); } catch(exception e) {....} }

daosf.java

public class daosf implements serializable { private static final long serialversionuid = 1l; private static sessionfactory sessionfactory; private static session hibsession; private static synchronized void initsessionfactory { configuration config = new configuration(); config.configure("hibernate.cfg.xml"); sessionfactory = config.buildsessionfactory(); hibsession = sessionfactory.getcurrentsession(); } public static sessionfactory getsessionfactory { initsessionfactory; homecoming sessionfactory; } public static session getsession() { homecoming hibsession; } }

could tell me, best practices in saving (updating, deleting) of object database saved object don't remain in memory?

try this. it's not yet perfect, think must rid of static session attribute in dao. see hibernate docs: http://docs.jboss.org/hibernate/envers/3.5/javadocs/org/hibernate/session.html:

it not intended implementors threadsafe. instead each thread/transaction should obtain own instance sessionfactory.

you can obtain session within dao itself, bean not have knowledge of underlying persistence mechanisms, did not want alter much.

bean.java

/* save datalist */ public void save() { session session = nlul; seek { session = daosf.getsessionfactory.opensession(); /* 1 instance per call, * ready garbage collection after leaving method */ dao mydao = new dao(session); mydao.save(datalist); } grab (exception e) {... } { if (session != null) session.close(); } }

dao.java

private session mysession = null; public dao(session mysession) { this.mysession = mysession; } public void save(list<? extends object> datalist) { (object dataitem : datalist) { save(dataitem); } } public void save(object dataitem) { seek { transaction tx = session.begintransaction(); this.mysession.save(dataitem); tx.commit(); } catch(exception e) {....} }

java jsf tomcat jvm

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -