No. 14 August growth topics

HashMap, Hashtable, ConcurrentHashMap the difference between theory?

HashTable
inherited from Dictionary, implements Map, Cloneable, Java.io.Serializable Interface

+ Linked list to achieve the underlying array, whether key or value can not be null, the sync thread-safe, thread-safe way to achieve is to lock the whole hashtable, inefficient, concurrentMap do the relevant optimized.
11 initial capacity expansion: newsize = oldsize * 2 + 1
two parameters that affect performance: initial capacity, load factor (0.75 default)
Calculation method for index: index = (the hash & 0x7FFFFFFF)% tab.length
the HashMap

+ Linked list implementation of the underlying array, there may be null keys and null values, thread-safe
initial expansion size is 16: newsize = oldsize * 2, size 2 n-th power of some of the
expansion for the entire map, and each time expansion, the original array recalculating element storage location, and re-inserted.
Analyzing element is inserted after the capacity is needed, if more no intervening invalid expansion
loading factor: 0.75 Default
Calculation Method index: index = hash & (tab.length- 1)
space for time: If you want to speed up the time to find the Key, may further lower load factor, increase the initial size, in order to reduce the probability of a hash collision.
ConcurrentMap

The bottom segment of the array using the linked list implementation +, thread safe.
By taking the entire map is divided into N Segment, may provide the same security thread efficiencies N times, 16 times the default.
Unlock read operation, modify the operation plus segment lock, allowing multiple modifications occur in parallel.
Expansion: the expansion segment (inner segment exceeds 0.75 Entry element array corresponding to the segment, trigger expansion, rather than the whole expansion), prior to insertion detecting whether the capacity is needed, to prevent invalid expansion.
(Some methods require cross-sections, such as size () and containsValue (), they may need to lock the entire table and not just a segment, which requires in order to lock all segments, after the operation is completed, and order the release of all segments lock).

SpringBoot and SpringCloud face questions

A. What is springboot

1 to simplify the development process and initial set up spring applied to specific embodiments for configuration (properties or yml file)
2. Create a separate method for operating a main spring procedures referenced
3. The embedded Tomcat without deploying war file
4. Simplified maven configuration
5. automatic function starter configured to add the corresponding spring automated configuration

Two .springboot What are commonly used starter

Maven repository can go search for the following plug-ins, pom files can rely on
Maven repository's official website: http://mvnrepository.com/
1.Spring-the Boot-Starter-web (embedded tomcat and web development needs servlet and jsp support)
2.spring -boot-starter-data-jpa (database support)
3.spring-the Boot-Starter-the Data-Redis (Redis database support)
4.spring-the Boot-Starter-the Data-Solr (Solr search application framework supports)
5.mybatis- spring-boot-starter (third mybatis integrated starter)

III. Springboot principle of automatic configuration

1. @ EnableAutoConfiguration This comment tells SpringBoot "guess" how would you want to configure Spring, based on what you've added jar dependencies. If the spring-boot-starter-web has been added Tomcat and Spring MVC, this comment will automatically assume you are developing a web application and add the appropriate spring set. Maven will automatically go read spring.factories file for each starter in the configuration file all need to be created in the spring of bean container

2. Use @SpringbootApplication annotation can be configured to address the root class or classes (my own words, where is the main class) problem of excessive head notes, equivalent to a @SpringbootApplication @ Configuration, @ EnableAutoConfiguration and @ComponentScan and have their default property value

Four .springboot way to read the configuration file

    springboot默认读取配置文件为application.properties或者是application.yml 
 
application.properties.PNG

mybatis springboot integrated process of
adding a starter maven mybatis dependent
<dependency>
<the groupId> org.mybatis.spring.boot </ the groupId>
<the artifactId> mybatis-springboot-Starter </ the artifactId>
<Version> 1.2.0 </ Version>
</ dependency>
Add mybatis interface of @Mapper annotation
information application.yml configuration data source

Five. Springboot how to modify the code [add] automatic restart function

    添加开发者工具集=====spring-boot-devtools

VI. MicroService

    以前的模式是 所有的代码在同一个工程中 部署在同一个服务器中 同一个项目的不同模块不同功能互相抢占资源
    微服务 将工程根据不同的业务规则拆分成微服务 微服务部署在不同的机器上 服务之间进行相互调用
    Java微服务的框架有 dubbo(只能用来做微服务),spring cloud(提供了服务的发现,断路器等)

VII. How springcloud achieve registration and discovery services

    服务在发布时 指定对应的服务名(服务名包括了IP地址和端口) 将服务注册到注册中心(eureka或者zookeeper)
    这一过程是springcloud自动实现 只需要在main方法添加@EnableDisscoveryClient  同一个服务修改端口就可以启动多个实例
    调用方法:传递服务名称通过注册中心获取所有的可用实例 通过负载均衡策略调用(ribbon和feign)对应的服务

Eight .ribbon and feign difference

Ribbon add maven dependent on spring-starter-ribbon using @RibbonClient (value = "service name") using RestTemplate remote service call corresponding method
feign add maven dependent on spring-starter-feign service provider to provide the caller to use the external interface on the interface @FeignClient ( "designated service")
the difference between the Ribbon and Feign:
Ribbon and Feign are calling for other services, but in different ways.
1. Start Notes different classes of use, Ribbon use the @ RibbonClient, Feign using a @EnableFeignClients.
2. specify the location of different services, Ribbon is @RibbonClient comment on the statement, Feign is the use of @FeignClient declared in the definition of the abstract methods of the interface.
3. Different invocation, Ribbon need to build their own http requests, simulate http request is then sent to other services using RestTemplate, steps quite tedious.
Feign is carried out on the basis of an improved Ribbon, using the interface the way, the other method of service is defined as the need to call an abstract method can be,
do not need to build their own http request. Note, however, that notes abstract methods, methods and method signatures to provide exactly the same services.

Effect of 91 .springcloud breaker

When a service call another service due to network problems for their own reasons or reasons caller will wait to be called
when the responder when more service requests to these resources
lead to more requests waiting knock-on effect this will happen (avalanche effect) is to solve this problem breaker breaker
has fully opened
up to a certain number of times within a certain period of time and can not be invoked repeatedly detected no sign of recovery breaker is fully open, then
it will not request the next request to the service half open, there are signs of recovery in a short time the circuit breaker will be part of the request sent to the service when
the circuit breaker is closed normally called when the service has been in a normal state can call the circuit breaker normally closed

 

SpringCloud Introduction and five common components

springcloud

springcloud is a master of micro-service architecture, a series of excellent components were integrated. springboot build on our familiar spring programmers based, relatively easy to get started.

With a few simple annotations, we can quickly look at commonly used in the application configuration module and build large distributed systems.

SpringCloud components is quite complex, with many subprojects. Focus on Netflix

Source @ Wang Lu -Louise. I draw out such a beautiful figure. . .

 

springcloud release notes:

springcloud project is a collection of several independent projects together, each item is independent, they carried out their own iteration and release. So springcloud inconvenient to use the version number to manage, but the use of the version name. In order to avoid conflicts and version number of subprojects.

 

Source version name is the name of the subway station in London, in alphabetical order. For example, the first Release version Angel, the second Release version Brixton. . .

When a version of the update accumulation of more or solve a serious bug when ServiceRelease will release a version, referred to as SR, a number appended with is the first release under the big version.

From the official website to see, F is based on the 2.0.x version springcloud build springboot, and before the building is based on the 1.5.x springboot

 

 

下面只简单介绍下经常用的5个

服务发现——Netflix Eureka客服端负载均衡——Netflix Ribbon断路器——Netflix Hystrix服务网关——Netflix Zuul分布式配置——Spring Cloud Config

Eureka

作用:实现服务治理(服务注册与发现)

简介:Spring Cloud Eureka是Spring Cloud Netflix项目下的服务治理模块。

由两个组件组成:Eureka服务端和Eureka客户端。

Eureka服务端用作服务注册中心。支持集群部署。

Eureka客户端是一个java客户端,用来处理服务注册与发现。

在应用启动时,Eureka客户端向服务端注册自己的服务信息,同时将服务端的服务信息缓存到本地。客户端会和服务端周期性的进行心跳交互,以更新服务租约和服务信息。

 

Ribbon

作用:Ribbon,主要提供客户侧的软件负载均衡算法。

简介:Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现。通过Spring Cloud的封装,可以让我们轻松地将面向服务的REST模版请求自动转换成客户端负载均衡的服务调用。

注意看上图,关键点就是将外界的rest调用,根据负载均衡策略转换为微服务调用。Ribbon有比较多的负载均衡策略,以后专门讲解。

 

 

Hystrix

作用:断路器,保护系统,控制故障范围。

简介:为了保证其高可用,单个服务通常会集群部署。由于网络原因或者自身的原因,服务并不能保证100%可用,如果单个服务出现问题,调用这个服务就会出现线程阻塞,此时若有大量的请求涌入,Servlet容器的线程资源会被消耗完毕,导致服务瘫痪。服务与服务之间的依赖性,故障会传播,会对整个微服务系统造成灾难性的严重后果,这就是服务故障的“雪崩”效应。

 

 

 

Zuul

作用:api网关,路由,负载均衡等多种作用

简介:类似nginx,反向代理的功能,不过netflix自己增加了一些配合其他组件的特性。

在微服务架构中,后端服务往往不直接开放给调用端,而是通过一个API网关根据请求的url,路由到相应的服务。当添加API网关后,在第三方调用端和服务提供方之间就创建了一面墙,这面墙直接与调用方通信进行权限控制,后将请求均衡分发给后台服务端。

Config

作用:配置管理

简介:SpringCloud Config提供服务器端和客户端。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。

这个还是静态的,得配合Spring Cloud Bus实现动态的配置更新。

Guess you like

Origin www.cnblogs.com/whymoney1000/p/11354730.html