We are working on a layered Java application that talks directly to Gemfire.
We need to be able to generate unique "long" sequence numbers, guaranteed unique across all nodes of the application. (Not all nodes are clustered)
Normally I would create a sequence in Oracle, but in this case, even though our Gemfire configuration has a connection to the relational database for write behind persistence, our application has no other knowledge of the database.
What would be the best way to generate those guaranteed unique long values, without going to the database?
The first question to ask yourself is do you really need a long sequence number (monotonically increasing long integer) or do you just need a globally unique identifier (like a UUID).
The most performant solution is going to be a globally unique id and I would just suggest using a GUID.
If you need a globally unique monotonically increasing long value (long sequence) then you will have to use some distributed locking and increment a value in the region. The method for this and performance depends on the type of region you are using.
Look at Region.replace(K, V, V). It can perform globally atomic updates to values under specific region definitions. You may need to consider a region that just has your sequences if your current region type is not sufficiently defined.
来源:https://stackoverflow.com/questions/28198508/how-can-i-get-a-unique-long-from-gemfire