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 7077497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:25:50+00:00 2026-05-28T06:25:50+00:00

I have a multiple contexts running in one tomcat instance each context need access

  • 0

I have a multiple contexts running in one tomcat instance each context need access to the same database.

I am running into problems with cashing because each context has its own instance of hibernate and ehcache at the moment.

This seems wrong they should only be one instance of hibernate and ehcache , this would also have better performance.

I would like to make a single instance of hibernate session factory available to all contexts, I think this can be done using a global JNDI resource in tomcat.

Is this a good way to solve this problem?

Also if anybody can provide any good resources for learning how to do this it would be much appreciated.

Update: I have managed to bind session factory to a global JNDI but a ConcurrentModificationException appears in the log during startup of tomcat.

...
INFO: schema update complete
Jan 11, 2012 2:03:19 PM org.hibernate.cache.UpdateTimestampsCache <init>
INFO: starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
Jan 11, 2012 2:03:19 PM org.hibernate.cache.StandardQueryCache <init>
INFO: starting query cache at region: org.hibernate.cache.StandardQueryCache
Constructed session factory ok sf=org.hibernate.impl.SessionFactoryImpl@430e0ad7
Jan 11, 2012 2:03:19 PM org.apache.catalina.mbeans.GlobalResourcesLifecycleListener createMBeans
SEVERE: RuntimeException java.util.ConcurrentModificationException
Jan 11, 2012 2:03:19 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 11, 2012 2:03:19 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.23
...
  • 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-28T06:25:51+00:00Added an answer on May 28, 2026 at 6:25 am

    I have solved the problem by using a LifecycleListener to create a singleton instance of session factory on start up.

    import org.apache.catalina.Lifecycle;
    import org.apache.catalina.LifecycleEvent;
    import org.apache.catalina.LifecycleListener;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    
    public class SessionFactorys implements LifecycleListener  {
    
        private static SessionFactory sessionFactory;
    
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    
        @Override
        public void lifecycleEvent(LifecycleEvent arg0) {
            if (Lifecycle.AFTER_START_EVENT==arg0.getType()) {
                sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
            }
            if (Lifecycle.BEFORE_STOP_EVENT==arg0.getType()) {  
                sessionFactory.close();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple threads (C# application running on IIS) running that all need to
I'm running into issues with multiple contexts and the main solution that comes up
I have a server with multiple Tomcat instances and each contains about 10 application
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have multiple branches of a project checked out, each under their own directory
I have a LINQ query running with multiple joins and I want to pass
I have a database client application. Some people will run multiple instances (i.e. processes)
I have multiple client databases that I need to hit on the fly and
I have two applications running in the same java virtual machine, and both use
A bit context. Let's say I have source files, which need to end up

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.