Example

Concurrency Rwlock

Demonstrates how helix-concurrency read/write lock helpers protect shared state and keyed resources. Shows ReadWriteLocked, ReadWriteStripedLocked, and both returning and void lock operations.
Group
Library
Path
examples/library/concurrency-rwlock

Overview

Helix Java application that shows how helix-concurrency read/write locks protect shared state and keyed resources.

Run this example from the shared examples build:

Run

Run this example from the shared examples build


./gradlew -p examples runExample -Pexample=library/concurrency-rwlock --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • using ReadWriteLocked for a single shared object
  • using read(...) and write(...) with both returning and void operations
  • using ReadWriteStripedLocked to lock different keys independently
  • protecting per-key inventory updates without forcing unrelated keys through the same lock
  • reading stable snapshots from both the shared state and striped-key state

Example Output

Helix concurrency rwlock example
shared.config={mode=warm, version=2}
inventory.sku-1=14
inventory.sku-2=4
inventory.snapshot={sku-1=14, sku-2=4}

Development

Building the Application

Run the following command to build the application:

Command

Building the Application


./gradlew clean build

Testing the Application

Run the following command to run the application tests:

Command

Testing the Application


./gradlew test
./gradlew integration

Running the Example

Run the application and inspect the lock-protected snapshots:

Command

Running the Example


./gradlew run