5 Replies Latest reply on Jan 25, 2005 1:43 AM by belaban

    Patch for DummyTransactionManager.java

    twundke

      Here's the second of my patches.

      The DummyTransactionManager uses a ThreadLocal to store transactions. However, the manager then stores a Map in the ThreadLocal, containing transactions keyed by Thread. Perhaps I'm missing something, but as far as I can see the Map just isn't needed as ThreadLocal stores values per thread itself.

      Here's a patch against revision 1.14 that removes the offending code.

      *** DummyTransactionManager.java.#.1.14 Thu Jan 20 14:17:51 2005
      --- DummyTransactionManager.java Thu Jan 20 11:32:31 2005
      ***************
      *** 6,13 ****
       import javax.naming.InitialContext;
       import javax.naming.NamingException;
       import javax.transaction.*;
      - import java.util.HashMap;
      - import java.util.Map;
       import java.util.Properties;
      
       /**
      --- 6,11 ----
      ***************
      *** 20,31 ****
       static DummyTransactionManager instance=null;
       static Logger log=Logger.getLogger(DummyTransactionManager.class);
      
      ! static ThreadLocal thread_local=new ThreadLocal() {
      ! protected synchronized Object initialValue() {
      ! Map map=new HashMap();
      ! return java.util.Collections.synchronizedMap(map);
      ! }
      ! };
      
       public DummyTransactionManager() {
       ;
      --- 18,24 ----
       static DummyTransactionManager instance=null;
       static Logger log=Logger.getLogger(DummyTransactionManager.class);
      
      ! static ThreadLocal thread_local=new ThreadLocal();
      
       public DummyTransactionManager() {
       ;
      ***************
      *** 185,193 ****
       * unexpected way.
       */
       public Transaction getTransaction() throws SystemException {
      ! Map map=(Map)thread_local.get();
      ! String thread=Thread.currentThread().toString();
      ! return (Transaction)map.get(thread);
       }
      
       /**
      --- 178,184 ----
       * unexpected way.
       */
       public Transaction getTransaction() throws SystemException {
      ! return (Transaction)thread_local.get();
       }
      
       /**
      ***************
      *** 240,253 ****
       }
      
       void setTransaction(Transaction tx) {
      - Map map=(Map)thread_local.get();
      - String thread=Thread.currentThread().toString();
      - // map.put(this, tx);
       if(tx == null) {
      ! map.remove(thread);
       }
       else {
      ! map.put(thread, tx);
       }
       }
      
      --- 231,241 ----
       }
      
       void setTransaction(Transaction tx) {
       if(tx == null) {
      ! thread_local.remove();
       }
       else {
      ! thread_local.set(tx);
       }
       }


      Tim.