1 Reply Latest reply on Jan 21, 2009 9:55 AM by j-n00b

    Sequence ID generator - Advice sought

    cbkihong

      Hello,

      I'm pretty new to Java EE myself so bear with me and rectify my misunderstandings. I would like to create a component that returns a unique sequence ID, that increments upon each call. As this is just one of the business functionality exposed to Web tier, later on I would like to have the Java EE server hosting those services to be replicated or clustered, so I thought implementing it as an EJB (EJB3) may be suitable to reserve this possibility. Is this a sound choice, otherwise what kind of an architecture do you suggest for this scenario?

      The desired behaviour is:

      * Scalable (say, through replication) with high availability
      * The counter that keeps track of largest seq no. should be persistent (across AS or server shutdown) and should not lose state (no two seq no. ever returned should be identical) at any time
      * It seems keeping the counter in database is an overkill (I've tried something similar in the past with some other language and I agree that is not performing well) and I would like the counter persisted in some other way

      Any suggestions for me? I intend to deploy on JBoss 4.2.3, JDK6. Thank you.

        • 1. Re: Sequence ID generator - Advice sought
          j-n00b

          Hi!

          Maybe this is not exactly what you want, but you could use the UUID generator for that.

          UUIDs aren't simple numbers, they are generated using different kind of information. The generator generates a new, random id on every call, so there is no problem in clustered environments. Considering its size (128 bit per id), it is very unlikely that the same uuid is generated twice.

          Have a look at >>> http://www.jboss.org/community/docs/DOC-11223 <<<, if you want to learn more.

          cheers,
          Andre