spring_boot_cloud(16)ribbon负载均衡与底层源码流程剖析
ribbon
- 负载均衡的框架
- 支持多种协议,如http、tcp等
- 提供负载均衡客户端
jar包
Gradle: com.netflix.ribbon:ribbon:2.3.0 外壳
Gradle: com.netflix.ribbon:ribbon-core:2.3.0 核心包
Gradle: com.netflix.ribbon:ribbon-eureka:2.3.0 和eureka的继承
Gradle: com.netflix.ribbon:ribbon-httpclient:2.3.0 http客户端
Gradle: com.netflix.ribbon:ribbon-loadbalancer:2.3.0 负载均衡器
Gradle: com.netflix.ribbon:ribbon-transport:2.3.0 其他协议的支持
spring_boot_cloud(15)eureka架构剖析与服务注册详解
eureka架构
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)拉取服务列表
spring_boot_cloud(14)Condition条件注解
concurrency(12)可重入读写锁对于AQS的实现分析
ReentrantReadWriteLock
实例:
1 | public class MyTest2 { |
concurrency(11)AQS-可重入锁
AQS(AbstractQueuedSynchronizer)
AQS和synchronized关键字C++的实现原理相似度是80%左右。
AbstractQueuedSynchronizer主要成员
- public class ConditionObject implements Condition, java.io.Serializable
一个AQS可以有多个Condition对象,也就意味着有多个等待队列 - static final class Node
Node是对阻塞线程的封装,Node内部有一个Thread的引用。 - private volatile int state; 同步状态,在不同的场景有不同的含义,精妙所在