Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-Hibernate application: Illegal access: this web application instance has been stopped already

I am handling the connections in proper way.
1. I am using 'Hibernate' connection pooling in my application. Whenever I get a connection from pool, I am returning back to pool after finishing the transaction.
2. I have monitored the database to check the connections. I have a 'Idle connection' time set to 60 seconds. I found no connection objects are running more than 60 seconds.

Still I am getting this error very often. And my web application is getting stopped. I have to restart tomcat every day once. However, I am looking for a permanent solution without restarting the tomcat.
Can any one explain the root cause? so that I can fix this.

Error Log:

INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.c3p0.ComboPooledDataSourceBeanInfo.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    ...
    ...
    ...
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

My hibernate-contect.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd
            ">

    <context:property-placeholder location="/WEB-INF/spring.properties" />

    <!-- Enable annotation style of managing transactions -->
    <tx:annotation-driven transaction-manager="transactionManager" />   

    <!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions -->
    <!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html -->                           
    <!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html -->
    <!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
                 p:dataSource-ref="dataSource"
                 p:configLocation="${hibernate.config}"
                 p:packagesToScan="com.turborep.turbotracker"/>

    <!-- Declare a datasource that has pooling capabilities-->   
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                destroy-method="close"
                p:driverClass="${app.jdbc.driverClassName}"
                p:jdbcUrl="${app.jdbc.url}"
                p:user="${app.jdbc.username}"
                p:password="${app.jdbc.password}"
                p:acquireIncrement="5"
                p:idleConnectionTestPeriod="60"
                p:maxPoolSize="100"
                p:maxStatements="50"
                p:minPoolSize="0" />

    <!-- Declare a transaction manager-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
                p:sessionFactory-ref="sessionFactory" />

</beans>

Edit1:
I got another error today. Here is the log:

[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JDBCExceptionReporter.java:logExceptions:234) Connections could not be acquired from the underlying database!
[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JDBCExceptionReporter.java:logExceptions:234) Connections could not be acquired from the underlying database!
[ERROR] [ajp-bio-8009-exec-4 08:27:13] (JobServiceImpl.java:getRxmasterID:4399) Cannot open connection
org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    ...
    ...
    ... 
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    ... 50 more

Sample code how I am using the connections:

@Resource(name="sessionFactory")
private SessionFactory itsSessionFactory;

@Override
public List<Userloginclone> getAllUserList() {
    itsLogger.debug("Retrieving all user list");
    Session aSession = null;
    List<Userloginclone> aQueryList = null;
    try {
        aSession = itsSessionFactory.openSession();
        Query aQuery = aSession.createQuery("FROM  Userloginclone");
        aQueryList = aQuery.list();
    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
    } finally {
        aSession.close();
    }
    return  aQueryList;
}

Please correct me if I am doing any thing wrong.

like image 665
vissu Avatar asked Mar 01 '13 09:03

vissu


2 Answers

  1. service tomcat stop

  2. ps -ef|grep java # look the process of java and kill all of them

  3. service tomcat start # and then it work

PS: You can look log in tomcat/logs/catalina.out and localhost-2018....log

like image 139
SwinBlackSea Avatar answered Oct 02 '22 16:10

SwinBlackSea


The problem you are facing is not related to database connections.

I guess you don't face this issue when you restart tomcat and don't redeploy the app, right?

The cause of it is redeploying the application in tomcat. Each time you redeploy the application new instance of a web application is created and the old one is stopped. There is probably an old class loaded by previous application somewhere or the application is not undeployed correctly.

Do you have some jar in tomcat/lib? Could you show the JobQuoteFormController and JobServiceImpl classes?

like image 28
František Hartman Avatar answered Oct 02 '22 14:10

František Hartman