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/odmg JTATxManager.java
Date Mon, 25 Jul 2005 00:02:14 GMT
arminw      2005/07/24 17:02:14

  Modified:    src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        JTATxManager.java
  Log:
  use WeakReference for all cache Transaction objects to all gc after use and to avoid redeployment
issues in appServer when treads are pooled and reused by the appServer.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.8.2.2   +30 -20    db-ojb/src/java/org/apache/ojb/odmg/JTATxManager.java
  
  Index: JTATxManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/JTATxManager.java,v
  retrieving revision 1.8.2.1
  retrieving revision 1.8.2.2
  diff -u -r1.8.2.1 -r1.8.2.2
  --- JTATxManager.java	11 Sep 2004 12:20:01 -0000	1.8.2.1
  +++ JTATxManager.java	25 Jul 2005 00:02:14 -0000	1.8.2.2
  @@ -21,12 +21,14 @@
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
   import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
  +import org.apache.commons.lang.SystemUtils;
   import org.odmg.TransactionNotInProgressException;
   
   import javax.transaction.Status;
   import javax.transaction.SystemException;
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
  +import java.lang.ref.WeakReference;
   
   /**
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
  @@ -38,7 +40,7 @@
    */
   public class JTATxManager implements OJBTxManager
   {
  -    private static Logger log = LoggerFactory.getLogger(JTATxManager.class);
  +    private Logger log = LoggerFactory.getLogger(JTATxManager.class);
       private static ThreadLocal txRepository = new ThreadLocal();
   
       /**
  @@ -47,11 +49,12 @@
        */
       public void deregisterTx(Object transaction)
       {
  -        TxBuffer buf = (TxBuffer) txRepository.get();
  -        if (buf != null)
  -        {
  -            buf.setInternTx(null);
  -        }
  +//        TxBuffer buf = (TxBuffer) txRepository.get();
  +//        if (buf != null)
  +//        {
  +//            buf.setInternTx(null);
  +//        }
  +        txRepository.set(null);
       }
   
       public void registerTx(TransactionImpl odmgTrans)
  @@ -73,9 +76,9 @@
           }
           if (log.isDebugEnabled())
           {
  -            log.debug("registerSynchronization was called with parameters" +
  -                    "\n  J2EETransactionImpl: " + odmgTrans +
  -                    "\n  Transaction: " + transaction);
  +            log.debug("registerSynchronization was called with parameters"
  +                    + SystemUtils.LINE_SEPARATOR +"J2EETransactionImpl: " + odmgTrans
  +                    + SystemUtils.LINE_SEPARATOR + "Transaction: " + transaction);
           }
           registerSynchronization(odmgTrans, transaction);
       }
  @@ -219,7 +222,7 @@
           if (log.isDebugEnabled()) log.debug("abortExternTransaction was called");
           if (odmgTrans == null) return;
           TxBuffer buf = (TxBuffer) txRepository.get();
  -        Transaction extTx = buf != null ? buf.externTx : null;
  +        Transaction extTx = buf != null ? buf.getExternTx() : null;
           try
           {
               if (extTx != null && extTx.getStatus() == Status.STATUS_ACTIVE)
  @@ -234,6 +237,7 @@
           catch (Exception ignore)
           {
           }
  +        txRepository.set(null);
       }
   
       public void configure(Configuration config)
  @@ -243,43 +247,49 @@
            */
       }
   
  +
       //************************************************************************
       // inner class
       //************************************************************************
  -
  -    final class TxBuffer
  +    private static final class TxBuffer
       {
  -        Transaction externTx = null;
  -        TransactionImpl internTx = null;
  +        private WeakReference externTx = null;
  +        private WeakReference internTx = null;
   
           public TxBuffer()
           {
           }
   
  +        /*
  +        arminw:
  +        use WeakReference to make sure that closed Transaction objects can be
  +        immediately reclaimed by the garbage collector.
  +        */
  +
           public TxBuffer(TransactionImpl internTx, Transaction externTx)
           {
  -            this.internTx = internTx;
  -            this.externTx = externTx;
  +            this.internTx = new WeakReference(internTx);
  +            this.externTx = new WeakReference(externTx);
           }
   
           public Transaction getExternTx()
           {
  -            return externTx;
  +            return (Transaction) externTx.get();
           }
   
           public void setExternTx(Transaction externTx)
           {
  -            this.externTx = externTx;
  +            this.externTx = new WeakReference(externTx);
           }
   
           public TransactionImpl getInternTx()
           {
  -            return internTx;
  +            return (TransactionImpl) internTx.get();
           }
   
           public void setInternTx(TransactionImpl internTx)
           {
  -            this.internTx = internTx;
  +            this.internTx = new WeakReference(internTx);
           }
       }
   }
  
  
  

---------------------------------------------------------------------
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