db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer RsIterator.java
Date Sun, 31 Jul 2005 18:55:54 GMT
arminw      2005/07/31 11:55:54

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE RsIterator.java
  Log:
  try to fix a performance issue caused by the RsIterator. See
  http://www.mail-archive.com/ojb-user%40db.apache.org/msg14014.html
  each RsIterator add itself as PB state listener, but never remove itself.
  Fix: remove listener if RsIterator resources are closed by the class itself.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.63.2.12 +30 -5     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.63.2.11
  retrieving revision 1.63.2.12
  diff -u -r1.63.2.11 -r1.63.2.12
  --- RsIterator.java	7 Jul 2005 17:16:21 -0000	1.63.2.11
  +++ RsIterator.java	31 Jul 2005 18:55:54 -0000	1.63.2.12
  @@ -151,6 +151,8 @@
        */
       private boolean autoRelease = true;
   
  +    private ResourceWrapper resourceListener;
  +
       /**
        * RsIterator constructor.
        *
  @@ -205,7 +207,8 @@
           PBStateListener to make sure that resources of this instance will be
           released. Add this as temporary PBStateListener.
           */
  -        m_broker.addListener(new ResourceWrapper(this));
  +        resourceListener = new ResourceWrapper(this);
  +        m_broker.addListener(resourceListener);
       }
   
       protected Class getTopLevelClass()
  @@ -780,11 +783,33 @@
        */
       public void releaseDbResources()
       {
  +        release(true);
  +    }
  +
  +    void release(boolean removeResourceListener)
  +    {
           if (!isInBatchedMode()) // resources are reused in batched mode
           {
               // If we haven't released resources yet, then do so.
               if (!this.resourcesAreReleased)
               {
  +                // remove the resource listener
  +                if(removeResourceListener && resourceListener != null)
  +                {
  +                    try
  +                    {
  +                        /*
  +                        when RsIterator is closed, the resource listener
  +                        was no longer needed to listen on PB events for clean up.
  +                        */
  +                        m_broker.removeListener(resourceListener);
  +                        this.resourceListener = null;
  +                    }
  +                    catch(Exception e)
  +                    {
  +                        logger.error("Error when try to remove RsIterator resource listener",
e);
  +                    }
  +                }
                   this.resourcesAreReleased = true;
                   if (m_rsAndStmt != null)
                   {
  @@ -1008,7 +1033,7 @@
               if(ref != null)
               {
                   RsIterator rs = (RsIterator) ref.get();
  -                if(rs != null) rs.releaseDbResources();
  +                if(rs != null) rs.release(false);
                   ref = null;
               }
           }
  @@ -1018,7 +1043,7 @@
               if(ref != null)
               {
                   RsIterator rs = (RsIterator) ref.get();
  -                if(rs != null) rs.releaseDbResources();
  +                if(rs != null) rs.release(false);
                   ref = null;
               }
           }
  @@ -1028,7 +1053,7 @@
               if(ref != null)
               {
                   RsIterator rs = (RsIterator) ref.get();
  -                if(rs != null) rs.releaseDbResources();
  +                if(rs != null) rs.release(false);
                   ref = null;
               }
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message