南贺神社

你写程序有写诗一样的感觉吗?

0%

eureka架构

eureka-construct.png

DiscoveryClient

The class that is instrumental for interactions with Eureka Server.
Eureka Client is responsible for a) Registering the instance with Eureka Server b) Renewalof the lease with Eureka Server c) Cancellation of the lease from Eureka Server during shutdown
d) Querying the list of services/instances registered with Eureka Server
DiscoveryClient是和Eureka服务通信的类的实现
a)注册到Eureka server
b)租约,续约
c)服务下线
d)拉取服务列表

Read more »

ReentrantReadWriteLock

实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class MyTest2 {
private ReadWriteLock lock = new ReentrantReadWriteLock();
public void method(){
try{
lock.readLock().lock();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("method");
}finally {
lock.readLock().unlock();
}
}

public static void main(String[] args) {
MyTest2 myTest2 = new MyTest2();
IntStream.range(0,10).forEach(i -> new Thread(myTest2::method).start());
}
}
Read more »

AQS(AbstractQueuedSynchronizer)

AQS和synchronized关键字C++的实现原理相似度是80%左右。

AbstractQueuedSynchronizer主要成员

aqs1.png

  • public class ConditionObject implements Condition, java.io.Serializable
    一个AQS可以有多个Condition对象,也就意味着有多个等待队列
  • static final class Node
    Node是对阻塞线程的封装,Node内部有一个Thread的引用。
  • private volatile int state; 同步状态,在不同的场景有不同的含义,精妙所在
    Read more »