File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
impl/core/src/main/java/io/serverlessworkflow/impl Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 1616package io .serverlessworkflow .impl ;
1717
1818import de .huxhorn .sulky .ulid .ULID ;
19+
1920import java .security .SecureRandom ;
20- import java .util .concurrent .locks . ReentrantLock ;
21+ import java .util .concurrent .atomic . AtomicReference ;
2122
2223/**
2324 * A {@link WorkflowInstanceIdFactory} implementation that generates Monotonic ULIDs as workflow
2627public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
2728
2829 private final ULID ulid ;
29- private ULID .Value current ;
30- private final ReentrantLock lock = new ReentrantLock ();
30+ private final AtomicReference <ULID .Value > currentUlid ;
3131
3232 public MonotonicUlidWorkflowInstanceIdFactory () {
3333 this .ulid = new ULID (new SecureRandom ());
34- this .current = ulid .nextValue ();
34+ this .currentUlid = new AtomicReference <>( ulid .nextValue () );
3535 }
3636
3737 public String get () {
38- this .current = ulid .nextMonotonicValue (this .current );
39- return current .toString ();
38+ return currentUlid .getAndUpdate (previousUlid -> ulid .nextMonotonicValue (previousUlid )).toString ();
4039 }
4140}
You can’t perform that action at this time.
0 commit comments