2013-03-01 63 views
9

私は適切な方法で接続を処理しています。
1.私はアプリケーションで 'Hibernate'接続プーリングを使用しています。私はプールから接続を得るたびに、トランザクションを終了した後にプールに戻っています。
2.私は接続を確認するためにデータベースを監視しています。私は60秒に設定された 'アイドル接続'時間があります。接続オブジェクトが60秒以上実行されていないことがわかりました。Spring-Hibernateアプリケーション:不正アクセス:このWebアプリケーションインスタンスはすでに停止しています

まだこのエラーが頻繁に発生しています。私のWebアプリケーションは停止しています。私は毎日tomcatを再起動する必要があります。しかし、私はtomcatを再起動せずに永続的な解決策を探しています。
根本原因を説明できる人はいますか?私はこれを修正することができます。

エラーログ:

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) 

マイ休止-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:
今日は別のエラーが発生しました。私は接続を使用していますか

[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 

サンプルコード:ここではログです

@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; 
} 

私が間違っている任意のものをやっているなら、私を修正してください。

答えて

4

まず、SpringのトランザクションマネージャとHibernateのOpenSessionInViewFilterを使用して、セッションとトランザクション管理を管理したいとします。これらの2つを使用すると、接続の管理について心配する必要はなく、SessionFactory.getCurrentSession()を使用してSessionを取得できます。

次に、p:testConnectionOnCheckout = "true"をdataSource Beanに追加する必要があります。

アプリケーションで起こっていることは、接続がいったん停止すると死んでしまうことです。これにより、デッド接続を再開できます。

+0

答えが私の問題を解決しなかった。しかし、私はこれをどのように修正するか考えています。 – vissu

+0

@vissuあなたが解決した場合、あなたのソリューションを共有できますか? – Halil

+0

@Halil May、私はこれを修正していないし、今はそのプロジェクトに取り組んでいない。私はそれを固定せずにしました。 :( – vissu

6

問題は、データベース接続に関連していません。

私はtomcatを再起動してもアプリケーションを再デプロイしないときにこの問題に直面しないでしょうか?

原因は、tomcatでアプリケーションを再デプロイするためです。アプリケーションを再デプロイするたびに、Webアプリケーションの新しいインスタンスが作成され、古いインスタンスが停止されます。おそらく、以前のアプリケーションによって古いクラスがロードされているか、アプリケーションが正しくアンデプロイされていない可能性があります。

tomcat/libにいくつかの瓶がありますか? JobQuoteFormControllerクラスとJobServiceImplクラスを表示できますか?

+0

はい私はtomcatを再起動します。このエラーは表示されません。しかし、2-3日後に再び来る。それからもう一度私はtomcatを再起動する必要があります。 – vissu

+0

2〜3日以内に再配置がありますか?何らかの理由でTomcatが独自にアプリケーションを再デプロイしないというログを確認できますか? –

+0

2〜3日で再展開はありません。クラッシュするたびに私は風袋を再始動します。 2〜3日後に再びクラッシュしています。 – vissu

関連する問題