Hazelcast IdGenerator
creates cluster wide unique IDs. Generated IDs are long type primitive values between 0 and Long.MAX_VALUE
. ID generation occurs almost at the speed of AtomicLong.incrementAndGet()
. Generated IDs are unique during the life cycle of the cluster. If the entire cluster is restarted, IDs start from 0 again or you can initialize to a value.
import com.hazelcast.core.IdGenerator;
import com.hazelcast.core.Hazelcast;
Config cfg = new Config();
HazelcastInstance hz = Hazelcast.newHazelcastInstance(cfg);
IdGenerator idGenerator = hz.getIdGenerator("customer-ids");
idGenerator.init(123L); //Optional
long id = idGenerator.newId();