Skip to content

Commit

Permalink
refactor: optimize the initialization process of SnowFlakeInstanceIdG…
Browse files Browse the repository at this point in the history
…enerator.
  • Loading branch information
llzcx committed Apr 22, 2024
1 parent 96e81ac commit f724707
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public class SnowFlakeInstanceIdGenerator implements InstanceIdGenerator {

private static volatile boolean initialize = false;

private static final Object lock = new Object();
private static final Object LOCK = new Object();

public void ensureWorkerIdInitialization() {
/**
* initialize the workerId and ensure that it is only initialized once.
*/
private void ensureWorkerIdInitialization() {
if (!initialize) {
synchronized (lock) {
synchronized (LOCK) {
if (!initialize) {
SNOW_FLOWER_ID_GENERATOR.init();
initialize = true;
Expand Down

0 comments on commit f724707

Please sign in to comment.