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=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <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> <maven.compiler.target>11</maven.compiler.target>… 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 »

Design Elevators

电梯调度 停车场 Elevator max people capacity max weight airstairs[only to living area], goods stair[to storage area] Building Each elevator can each level or certain levels? Inside building the button controls all elevator or just one elevator. Scheduler same direction > static > different direction when elevator is running, can we press the button for different… 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 »

Token Bucket

public class TokenBucket { private long maxBucketSize; private long refillRate; // per second private long currentBucketSize; private long lastRefillTimestamp; synchronized public boolean allowRequest(int token) { refill(); if (currentBucketSize >= token) { currentBucketSize -= token; return true; } return false; } private void refill() { long now = System.nanoTime(); double add = (now – lastRefillTimestamp) /… Read More »

groupon design

rule: { rule_id, type: discount/one-time value: 30%/50$ limited_user: [usr1, usr2] limited_user_grp: [grp1, grp2] number_of_usage: 1, service: [LYFT, CHIPOTLE] } groupon: { g_id, code: XMASCODE rule_id: xxx expire_date: 2021/12/31 } usage: { user_id, groupon_id, time }

ConcurrentHashMap

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 »