File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
impl/core/src/main/java/io/serverlessworkflow/impl Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 1717
1818import de .huxhorn .sulky .ulid .ULID ;
1919import java .security .SecureRandom ;
20+ import java .util .concurrent .locks .ReentrantLock ;
2021
2122/**
2223 * A {@link WorkflowInstanceIdFactory} implementation that generates Monotonic ULIDs as workflow
2324 * instance IDs.
2425 */
2526public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
2627
27- private final SecureRandom random = new SecureRandom () ;
28- private final ULID ulid = new ULID ( random ) ;
29- private ULID . Value previousUlid ;
28+ private final ULID ulid ;
29+ private ULID . Value current ;
30+ private final ReentrantLock lock = new ReentrantLock () ;
3031
31- @ Override
32- public synchronized String get () {
33- if ( previousUlid == null ) {
34- previousUlid = ulid . nextValue ();
35- } else {
36- previousUlid = ulid . nextMonotonicValue ( previousUlid );
37- }
38- return previousUlid .toString ();
32+ public MonotonicUlidWorkflowInstanceIdFactory () {
33+ this . ulid = new ULID ( new SecureRandom ());
34+ this . current = ulid . nextValue ();
35+ }
36+
37+ public String get () {
38+ this . current = ulid . nextMonotonicValue ( this . current );
39+ return current .toString ();
3940 }
4041}
You can’t perform that action at this time.
0 commit comments