Class UidGenerator

java.lang.Object
bitronix.tm.utils.UidGenerator

public class UidGenerator extends Object
Helper that offers UID generation (GTRID, XID, sequences) needed by the transaction manager.

Generated UIDs are at most 64 bytes long and are made of 3 subparts: the current time in milliseconds since Epoch, a JVM transient atomic sequence number and the configured bitronix.tm.serverId.

The reliance on the system clock is critical to the uniqueness of the UID in the network so you have to make sure all servers of the network running this transaction manager have their clock reasonably in sync. An order of 1 second synchronicity is generally fine.

Author:
lorban
  • Constructor Details

    • UidGenerator

      public UidGenerator()
  • Method Details

    • generateUid

      public static Uid generateUid()
      Generate a UID, globally unique. This method relies on the configured serverId for network uniqueness.
      Returns:
      the generated UID.
    • generateXid

      public static BitronixXid generateXid(Uid gtrid)
      Generate a XID with the specified globalTransactionId.
      Parameters:
      gtrid - the GTRID to use to generate the Xid.
      Returns:
      the generated Xid.