I would need to know if the SequenceUtil class to generate numbers in a sequence is protected from concurrent reads.
I have a scenario in ClaimCenter in which I need to access these sequences on every claim and they could be accessed concurrently from several sources such as the user interface, asynchronous workflows and REST APIs. I need to guarantee the sequence never produces values already used.
I was considering to implement this via a ReentrantLock to protect the call to SequenceUtil but I would like to know if this is not a recommended approach performance-wise or if it is not even necessary (in case the sequence access is already protected). I’ve seen the use of ReentrantLocks is discouraged in this post Concurrent Data Change exception, since it can negatively affect performance or be ineffective.
Thank you very much in advance.
The SequenceUtil is protected from concurrent reads, because the sequence number generation is ultimately handled by the database (either SQL Server or Oracle for on-premise, Aurora for Cloud) running ClaimCenter. All requests for a new number in the sequence are handled by the database, even if multiple requests for a new sequence number are received close together on different application nodes. The database sorts out which request for a new sequence number was “first” and sends each request it’s own unique sequence number.
Also, I believe the ReentrantLock would only really work in a situation where one JVM is being used (a single node instance of ClaimCenter). Since every instance of ClaimCenter in production uses multi-node clustering (multiple JVMs accessing the same DB or DB Cluster) I am not sure that ReentrantLock is even a viable solution for your use case.
If you provide more details around the statement, I will edit my answer to provide more help:
“I have a scenario in ClaimCenter in which I need to access these sequences on every claim and they could be accessed concurrently from several sources such as the user interface, asynchronous workflows and REST APIs. I need to guarantee the sequence never produces values already used.”
The SequenceUtil is designed in such a way to guarantee that each call for a new sequence number produces a new value and that subsequent calls will not re-use any previously provided values.