Mysql doesn’t support sequences as Oracle and MsSQL.But we can simulate this using some implementations i found over the internet and improuved.
There are 2 options to do this thing:
1.Using an auxiliary table named sequence
- create a table named sequence in your database
- table sequence (id:BIGINT)
- set the id with value equal to your start value (default)
- every time you need a new id execute a transaction like this
select id from sequence
update sequence set id=id+1
- every time a thread asks for an id a distinct long will be auto incremented
This procedure was tested on multiple threads concurrently(over 1000000),it depends on your settings of your MySql.