Oliver Zeigermann wrote:

On 5/20/05, David J. M. Karlsen <[EMAIL PROTECTED]> wrote:
Hi!

I keep getting ResourceManagerExceptions with "Duplicate transaction
id". I took a look at the implementation of FileResourceManager - and
generatedUniqueID only returns system.getCurrentMillis() - which isn't
random enough in a multithreaded environment.

Hmmm, I wonder why this is so? Looking at generatedUniqueTxId() it
checks if the transaction Id already is in use by

           } while (getContext(txId) != null);

Are you sure this is the reason for your exceptions?
Hmm, yeah, but still - I cannot see why txId should be unique, the code is:

public String generatedUniqueTxId() throws ResourceManagerSystemException {
       assureRMReady();
       String txId;
       synchronized (globalTransactions) {
           do {
               txId = Long.toHexString(System.currentTimeMillis);
               // XXX busy loop
           } while (getContext(txId) != null);
       }
       return txId;
   }


you can apply my patch.
It uses doomdark.org 's UUIDGenerator. (the site is down at the moment).

This should probably be changed into a UUID algorithm or something.

This would be a good idea in any case :)

Also - the LoggerInterface has a createLogger method - but this is an
instance method - so the logging stuff should probably be changed into a
factory that creates logger of a specified type?

Would be cleaner, yes.

I also miss a LoggerFacade for jakarta's own Commons Logging (which
would make the other classes redundant).

Not quite. Commons Logging does not map to the Jakarta Slide logging
system which makes heavy use of commons transaction. That's why there
is such a LoggerFacade. Aside, a Commons logging implementation would
be a good idea :)

Anyone?

If you could propose any patches I would be happy to consider them ;)
I'll have a look into the logging as well.
Index: FileResourceManager.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/FileResourceManager.java,v
retrieving revision 1.6
diff -u -r1.6 FileResourceManager.java
--- FileResourceManager.java    7 Jan 2005 13:32:33 -0000       1.6
+++ FileResourceManager.java    21 May 2005 16:07:22 -0000
@@ -42,6 +42,10 @@
 import java.util.Iterator;
 import java.util.Collections;
 
+import org.doomdark.uuid.UUIDGenerator;
+import org.doomdark.uuid.UUID;
+
+
 import org.apache.commons.transaction.locking.GenericLock;
 import org.apache.commons.transaction.locking.GenericLockManager;
 import org.apache.commons.transaction.locking.LockException;
@@ -881,7 +885,9 @@
         String txId;
         synchronized (globalTransactions) {
             do {
-                txId = Long.toHexString(System.currentTimeMillis());
+                //txId = Long.toHexString(System.currentTimeMillis());
+               UUID uuid = 
UUIDGenerator.getInstance().generateRandomBasedUUID(); 
+               txId = uuid.toString();
                 // XXX busy loop
             } while (getContext(txId) != null);
         }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to