Do you need guaranteed sequential or monotonic numbers?

If so, ignore this post. If unique is good enough, read on...

> Hi folks
> i am sure this has been discussed before if so please point me to the
> correct thread / message,
> Recently i came across a peculiar problem we have several transactions
> which required sequence number , now this number has to be generated and
> handed out fast enough!!!   So it kind of rules out putting it in a db and
> accessing it!!!

Not if you grab bunches of sequence numbers at once, say 1000.

> So i hit upon a simple solution of putting a sequence number in a hash
> table and looking up the number whenever i required one!!
>
> The situation was okie with a few users but with a few more users it was no
> more thread safe!!!  So i synchronised on the method...
>
> Now how do i do the following
> 1)  Make it instance safe as more than one bean could be in my pool and
> they could do a update it and lead to dirty reads??

Would using entity beans avoid this problem?

> 2)  How do i make sure it is cluster safe??

Each cluster grabs it's own bunches of numbers -- the DB synchronizes this.

> 3)  How do i ensure even if the server goes down the last value of the
> transaction number gets saved in the db and i can start afresh from there
> on!!!

You save the last number when you grab the bunch. If you crash/shut down the 
remaining numbers in the bunch just never get used.

> 4) I am trying to [not?] do a sequence number in Oracle a) becos it is 
database
> specific
> b)  the overhead and contention on it will be quite high!!
>
> Is there any other approach ,  please let me in how u folks go about it
> normally...

The above is what I do -- but I haven't done it with EJB's yet.

Tom

-- 
Tom Davies -- [EMAIL PROTECTED]

http://mwmbers.optushome.com.au/tomdavies


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to