Category Archives: java

DynamodDb access in Java(Code)

Assume we have below data in DynamoDb. All fields are String type. PK is ID, SK is name. We use DynamoDbEnhancedAsyncClient to access DynamoDb data. To get a specific record with (PK, SK): public static void testGetItem() throws Exception { CompletableFuture<Record> recordFuture = table.getItem(Key.builder() .partitionValue(“001”) .sortValue(33) .build()); System.out.println(recordFuture.get()); } To query only on PK: public static… Read More »

DynamoDB access in Java(structure)

1. dynamodb vs dynamodb-enhanced 1)., dynamodb 2)., dynamodb-enhanced, a high-level library. Can map class to DynamoDb tables. Introducing enhanced DynamoDB client in the AWS SDK for Java v2 2. Client vs Table DynamoDbClient/DynamoDbEnhancedClient is like databases access. Think you know the username/password to the database. DynamoDbTable/DynamoDbAsyncTable is the table you will operate on.… Read More »

dependencyManagement as jar

Without specifying <packaging>xxx</packaging> in pom, the default is jar. For project1, it is deployed to nexus. Then project2 can uses it as normal dependency rather than parent. project2 can still uses the version, scope inside dependencyManagement in project1. See below. project1/pom.xml <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”″ xmlns:xsi=”” xsi:schemaLocation=””> <modelVersion>4.0.0</modelVersion> <groupId>com.test.pengli</groupId> <artifactId>project1</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>11</maven.compiler.source> <>11</>… Read More »

dependencyManagement vs dependencies

dependencies uses the dependencies. dependencyManagement doesn’t include dependencies in project. It is mainly defines dependencies and its version, scope. Sub project specifies parent to it. When sub project defines dependencies, it won’t need to specify version, scope. project1/pom.xml This pom.xml has <packaging>pom</packaging> property. In this case, it can be used as parent in sub project. <?xml version=”1.0″… Read More »

Producer, Consumer with ReentrantLock, Condition

public class PC { public static void main(String[] args) { ReentrantLock lock = new ReentrantLock(); Condition added = lock.newCondition(); Condition removed = lock.newCondition(); int[] resource = new int[1]; Consumer c1 = new Consumer(lock, added, removed, resource); Producer p1 = new Producer(lock, added, removed, resource); Producer p2 = new Producer(lock, added, removed, resource); new Thread(c1).start(); new… Read More »


Each segment has multiple entries. Each entry, it starts with a LinkedList. When it has too many, it changes to Black-Red-Tree. When write, if two writes are for different segment, then it allows. When multiple writes to same segment, it uses CAS(compare-and-set) to write and handle conflict. Each operation on segment has a counter. The… Read More »

ReentrantLock, ReentrantReadWriteLock

RentrantLock is almost the same as synchronized keyword. Only difference is that synchrnozied keyword needs a block. It maintains a queue for the threads. RentrantLock lock = new ReentrantLock(); lock.lock(); try { do something.. } finally { lock.release(); } ReentrantReadWriteLock. It also maintains a queue for threads. When it has queue: [readThread1, readThread2, writeThread3, readThread4]… Read More »

Background run, nohup, &

nohup, means “no hangup”. Means even logout, let it run. &, run in background. For instance: nohup java -jar abc.jar &