publicclassLockClientExample { @Test publicvoidusageExample() throwsInterruptedException, IOException { // Inject client configuration to the builder like the endpoint and signing region finalDynamoDbClient dynamoDB =DynamoDbClient.builder() .region(Region.US_WEST_2).endpointOverride(URI.create("http://localhost:4567")) .build(); // Whether or not to create a heartbeating background thread finalboolean createHeartbeatBackgroundThread =true; //build the lock client finalAmazonDynamoDBLockClient client =newAmazonDynamoDBLockClient( AmazonDynamoDBLockClientOptions.builder(dynamoDB, "lockTable") .withTimeUnit(TimeUnit.SECONDS) .withLeaseDuration(10L) .withHeartbeatPeriod(3L) .withCreateHeartbeatBackgroundThread(createHeartbeatBackgroundThread) .build()); //try to acquire a lock on the partition key "Moe" finalOptional<LockItem> lockItem = client.tryAcquireLock(AcquireLockOptions.builder("Moe").build()); if (lockItem.isPresent()) { System.out.println("Acquired lock! If I die, my lock will expire in 10 seconds."); System.out.println("Otherwise, I will hold it until I stop heartbeating."); client.releaseLock(lockItem.get()); } else { System.out.println("Failed to acquire lock!"); } client.close(); } }