1 Reply Latest reply on Jun 16, 2006 10:02 AM by Ann Connell

    Migration Problem - intermittent database access

    Ann Connell Newbie

      I'm currently migrating an application from JBOSS 4.0.0DR3 to JBOSS 4.0.4.GA, and am having intermittent problems with database access on the new version - some parts of code manage to get the connection successfully while other parts (which use the same method to get a connection) have the connection closed by the CachedConnectionManager. The output in this case is as shown below

      Code used to get connection (sometimes works)
      --------------------------------------------------

      public static Connection getDBConnectionByNaming() throws SQLException
      {


      Connection conn=null;
      opens++;
      System.out.println("DBConnection: Opens " + opens);

      try
      {

      if (NAMING_CONTEXT ==null){
      NAMING_CONTEXT=PropertyManager.getProperty Constants.DB_NAMING_CONTEXT);
      }

      InitialContext ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup(NAMING_CONTEXT);
      conn = ds.getConnection();

      }catch (NamingException ex)
      {
      System.out.println("DBConnection: Naming Exception");
      ex.printStackTrace();
      } catch ( Exception e ) {
      System.out.println("DBConnection: N** Exception");
      e.printStackTrace();
      }

      return conn;

      } // end getDBConnectionByNaming()





      JBOSS output on error
      ---------------------------------

      s_4_0_4_GA date=200605151000)] Started in 1m:38s:862ms
      10:27:06,658 INFO [TilesRequestProcessor] Tiles definition factory found for re
      quest processor ''.
      10:27:09,301 INFO [STDOUT] DBConnection: Opens 1
      10:27:21,739 INFO [CachedConnectionManager] Closing a connection for you. Plea
      se close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@7d4275

      java.lang.Throwable: STACKTRACE
      at org.jboss.resource.connectionmanager.CachedConnectionManager.register
      Connection(CachedConnectionManager.java:290)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
      onnection(BaseConnectionManager2.java:400)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
      nManagerProxy.allocateConnection(BaseConnectionManager2.java:812)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
      erDataSource.java:88)
      at com.ivity.util.db.DBConnectionManager.getDBConnectionByNaming(DB
      ConnectionManager.java:131)
      at com.ivity.rserver.group.GroupControllerBean.getGroups(Group
      ControllerBean.java:120)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
      tatelessSessionContainer.java:237)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      ke(CachedConnectionInterceptor.java:158)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
      elessSessionInstanceInterceptor.java:169)
      at org.jboss.ws.server.ServiceEndpointInterceptor.invoke(ServiceEndpoint
      Interceptor.java:64)
      at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidation
      Interceptor.java:63)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:121)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:350)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
      81)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:168)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
      ryFinderInterceptor.java:136)
      at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:6
      48)
      at org.jboss.ejb.Container.invoke(Container.java:954)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch
      er.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
      java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(Loca
      lInvoker.java:169)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)

      at org.jboss.invocation.InvokerInterceptor.invokeLocalMarshalled(Invoker
      Interceptor.java:292)
      at org.jboss.invocation.MarshallingInvokerInterceptor.invoke(Marshalling
      InvokerInterceptor.java:61)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
      java:61)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:7
      0)
      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessi
      onInterceptor.java:112)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
      at $Proxy104.getGroups(Unknown Source)
      at Admin.GroupAdminAction.execute(GroupAdminAction.java:47)
      at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
      tProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
      va:236)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:119
      6)
      at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
      lter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
      alve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
      alve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
      yAssociationValve.java:175)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
      torBase.java:432)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
      e.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
      ava:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
      ava:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
      ve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
      a:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
      :869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
      rocessConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
      int.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
      kerThread.java:112)
      at java.lang.Thread.run(Thread.java:534)

        • 1. Re: Migration Problem - intermittent database access
          Ann Connell Newbie

          The problem here was in the closing of the connection. It was done as follows:

          finally {

          try {
          prepStmt.close();
          result.close();
          conn.close();
          }
          catch (Exception e) {
          // ignore
          }
          }

          The problem was that the result.close() should come before the prepared statement close - because infact the resultset gets closed when the prepared statement is closed and i was getting an exception when trying to close (an already closed) result set. Although this is logical, i'm not sure why the behaviour differs between deployments?