This is a simple example that demonstrates the use of transactions to protect consistency during concurrent access and modification of data. Since a region may configured across multiple servers and multiple clients may interact with that region independent of each other, data integrity relies on synchronization of modifications between all actors.
An example of how data can become inconsistent during concurrent interaction is as follows:
This example starts five child processes, each of which tries one thousand times to get the current value of a counter, increment that value, and the put the incremented value back into the region. To protect data consistency, the incrementing is abandoned and retried if another child has already incremented the value or if another child is simultaenously trying to increment the value. This example, which should take about a dozen seconds, reports the final value of the counter to show that all of the children's increments were consistently applied.
This example assumes you have installed Java and Geode.
geode-examples/transaction directory, build the example and run unit tests.
$ ../gradlew build
Next start a locator, start a server, and create a region.
$ gfsh run --file=scripts/start.gfsh
Run the example to demonstrate transactions.
$ ../gradlew run
Shut down the system.
$ gfsh run --file=scripts/stop.gfsh