Claude-skill-registry distributed-locking-rfc-44

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/distributed-locking-rfc-44" ~/.claude/skills/majiayu000-claude-skill-registry-distributed-locking-rfc-44 && rm -rf "$T"
manifest: skills/data/distributed-locking-rfc-44/SKILL.md
source content

Distributed Locking (RFC-44)

RFC-44 compliant distributed locking patterns for Java services.

When to use this skill

  • Implementing distributed locking for scheduled jobs
  • Migrating from legacy locking mechanisms
  • Choosing between PostgreSQL and Redis locking
  • Migrating from Fabric8 leader election
  • Migrating from incubated in-repo libraries
  • When asked to "migrate locks to be RFC-44 compliant"

Skill Contents

Sections

Available Resources

📚 references/ - Detailed documentation


Quick Start

1. Add Dependencies (PostgreSQL)

# gradle/libs.versions.toml
[versions]
distributed-locking-api = "2.0.0"
distributed-locking-postgres-jooq = "2.0.0"

[libraries]
distributed-locking-api = { module = "com.bitso.commons:distributed-locking-api", version.ref = "distributed-locking-api" }
distributed-locking-postgres-jooq = { module = "com.bitso.commons:distributed-locking-postgres-jooq", version.ref = "distributed-locking-postgres-jooq" }

2. Create Configuration Bean

@Configuration
public class DistributedLockConfiguration {
    @Bean
    DistributedLockManager<Long> distributedLockManager(
            @Qualifier("write-dslcontext") DSLContext dslContext) {
        return new JooqPostgresSessionDistributedLockManager(dslContext);
    }
}

3. Use in Scheduled Jobs

@Scheduled(cron = "${job.cron:-}", zone = "UTC")
public void scheduledJob() {
    try (var lock = distributedLockManager.tryLock("job-lock")) {
        if (!lock.acquired()) {
            log.info("Job already running on another instance");
            return;
        }
        doWork();
    }
}

Implementation Options

RFC-44 supports two valid locking implementations:

ImplementationWhen to Use
PostgreSQL Advisory Locks (Default)Services with PostgreSQL available
Redis Locking (Allowed)Services without PostgreSQL, or with justified Redis use case

Important: Redis-based locking is NOT deprecated. It is explicitly supported per RFC-44.

Common Patterns

Try-with-resources Pattern

try (var lock = distributedLockManager.tryLock("lock-key")) {
    if (!lock.acquired()) {
        return;
    }
    executeTask();
}

Vavr Pattern

Try.withResources(() -> distributedLockManager.tryLock("lock-key"))
    .of(lock -> Option.of(lock)
        .filter(DistributedLock::acquired)
        .onEmpty(() -> log.info("Lock not acquired"))
        .peek(l -> doWork()));

References

ReferenceDescription
references/migration-workflow.mdStep-by-step migration guide
references/lock-patterns.mdRFC-44 lock patterns
references/redis-integration.mdRedis-based locking setup
references/troubleshooting.mdCommon issues and solutions

Related Rules

Related Skills

SkillPurpose
gradle-standardsDependency configuration
java-testingTesting lock mechanisms
<!-- AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY --> <!-- Source: bitsoex/ai-code-instructions → java/skills/distributed-locking-rfc-44/SKILL.md --> <!-- To modify, edit the source file and run the distribution workflow -->