Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:48:59+00:00 2026-05-23T19:48:59+00:00

I’m trying to tune my JSF application memory consuption by setting JVM arguments because

  • 0

I’m trying to tune my JSF application memory consuption by setting JVM arguments because I’m getting out of memory error.

I’m able to increase memory heap and restart the server twice a day, but it’s not a 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 to work fine, tenured space is at 0 MB, eden space is continuosly cleared but survivor space is still growing and when it reach its limit, object are moved to tenured space and never been released. And after half a day of running application I get the out of memory error. So I have to schedule automatical restarts of tomcat server.

enter image description here

So I think, there must be some problem in my application, because its memory consuption is too high for such a small appl (about thousands movements in database per day).

There is part of my code:

Bean.java

/* save datalist */
public void save() 
{
  session = DaoSF.getSessionFactory.openSession();
  try
  {
    Dao.save(dataList);
  }
  catch  (Exception e) {...}
  finally
  {
    session.close();
  }
}

Dao.java

public static void save(List<? extends Object> dataList)
{  
  for (Object dataItem : dataList) 
  {  
    save(dataItem);  
  }  
}  
public static void save(Object dataItem) 
{ 
  try 
  { 
    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;
    return sessionFactory;
  }

  public static Session getSession() 
  {
    return hibSession;
  }
}

Could you tell me, what are the best practices in saving (updating, deleting) of object to database so that the saved object don’t stay in memory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:49:00+00:00Added an answer on May 23, 2026 at 7:49 pm

    Try this. It’s not yet perfect, but I think you must get rid of the static session attribute in Dao. See hibernate docs: http://docs.jboss.org/hibernate/envers/3.5/javadocs/org/hibernate/Session.html:

    It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.

    You can also obtain the session inside Dao itself, so that Bean does not have any knowledge of the underlying persistence mechanisms, but I did not want to change that much.

    Bean.java

    /* save datalist */
    public void save() {
        Session session = nlul;
        try {
            session = DaoSF.getSessionFactory.openSession();
            /* one instance per call, 
             * ready for garbage collection after leaving this method
             */
            Dao mydao = new Dao(session);
            mydao.save(dataList);
        } catch  (Exception e) {...
        } finally {
            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) {  
        for (Object dataItem : dataList) {  
            save(dataItem);
        }  
    }  
    
    public void save(Object dataItem) { 
        try  { 
            Transaction tx = session.beginTransaction();  
            this.mysession.save(dataItem);  
            tx.commit();  
        }  
        catch(Exception e) {....}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.