cancel
Showing results for 
Search instead for 
Did you mean: 

Thread safe unique sequence generation

narayana_giri
Champ in-the-making
Champ in-the-making
Please let me know what is the best and simple thread safe unique sequence generation approach.

Appreciate response with links/sample code.
1 REPLY 1

kaynezhang
World-Class Innovator
World-Class Innovator
If you want your  sequence generation class to be survived between server restart ,you  can consider to use db seqence(oracle sequence,mysql  LAST_INSERT_ID() ..)
If not,You can use Atomic Integer ,it is thread safe.you can define a singleton class and use AtomicInteger 's getAndIncrement() method to generate sequence number.