MoienGK
MoienGK

Reputation: 4654

my jsp page never loads

I have a J2EE web application, that runs on a shared Tomcat on a server. Sometimes the website never loads, takes almost 5-10 minutes! It never loads or show any error during that time, and after trying many times, it finally shows the error: (111) connection refused. I dont know what the cause is. Can anyone tell me what the problem could be? Is it my application or the hosting company ? By the way the website keeps working for 1,2 days and then the above scenario happens.

The application is JSP and uses Hibernate to connect to a MySQL database.

Upvotes: 0

Views: 691

Answers (3)

MoienGK
MoienGK

Reputation: 4654

i finally find the problem :

public class HibernateUtil {
  private static final SessionFactory sessionFactory = buildSessionFactory();

  private static SessionFactory buildSessionFactory() {
    try {
      // Create the SessionFactory from hibernate.cfg.xml
      return new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
      // Make sure you log the exception, as it might be swallowed
      System.err.println("Initial SessionFactory creation failed." + ex);
      throw new ExceptionInInitializerError(ex);
    }
  }

  public static SessionFactory getSessionFactory() {
    return sessionFactory;
  }
}

as you can see above the getSessionFactory() method always leads to buildSessionFactory() so every time that i called hibernateUtil.getSessionFactory() any where in my code, hibernate has made more and more connections to database and it made database non responsive :)

Upvotes: 0

Donal Fellows
Donal Fellows

Reputation: 137597

I've observed something very much like this with my deployment server, and not yet had the opportunity to chase it down properly (that server only has the JRE installed, not the full JDK, and it's heavily firewalled too). From watching the logs, I know that it is apparently just hanging during the initialization stage of the (principal) webapp, and nothing else is happening during that time (from watching system logs; the whole system is quiescent at the time, with no processes being runnable) and I know that it only seems to happen when booting the whole container, and not when installing the webapp into an already-running container.

That leads me to speculate that the problem is due to some kind of unpleasant interaction between the Java runtime and the intensive class loading going on inside the webapp. For example, if there's JIT data that's getting flushed by the GC from a weak hash map before it's really finished with, that could push everything into some slower path through the code with (many) more wait states. (I've hunted such things in the past; they're very hard to track down because everything is still behaving correctly, if non-optimally, and it could well be a problem across many levels of an application.)

My best advice is to

  1. be careful about boot order (e.g., make sure that the DB is up and stable before bringing up Tomcat)
  2. don't use dynamic/lazy loading of webapps (it destroys reproducibility)
  3. be patient: don't try to access the webapp until it indicates that it is ready (if you can, lock out connections to the Tomcat instance until it has brought up all the webapps inside it).

Upvotes: 1

Danilo Tommasina
Danilo Tommasina

Reputation: 1760

Try running the jstack command on the server when as soon as it hangs. The command will create a very helpful thread dump of your running (or blocked) threads and you can figure out what is causing the trouble.

Upvotes: 1

Related Questions