This article should take about 6 minutes to read.


Reprinted from: https://juejin.cn/post/6844903882162716685

1.Spring life cycle

Spring is the most popular and powerful lightweight container framework in Java, so it is necessary to be familiar with the Spring lifecycle.

  • First, after the container is started, the bean is initialized

  • Inject properties as defined by the bean

  • Detect whether the object implements the xxxAware interface and inject the relevant xxxAware instance into the bean, such as BeanNameAware

  • In the previous steps, the bean object was constructed correctly, and you can do some more custom method processing by implementing the BeanPostProcessor interface. Such as: postProcessBeforeInitialzation.

  • PostConstruct, afterPropertiesSet,init-method and other methods can be implemented after the pre-processing of BeanPostProcessor to add our custom logic.

  • By implementing the BeanPostProcessor interface, rear postProcessAfterInitialzation processing

  • Then the Bean is ready to be used.

  • After the container closes, if the Bean implements the DisposableBean interface, the destroy() method on that interface will be called back

  • By specifying a function for destroy-method, you can execute the specified logos before the bean is destroyed

2.TCP three handshakes and four waves

TCP’s three-way handshake and four-way wave is something every programmer should be familiar with.

Three handshakes:

  • The client enters the SYN_SEND state after the first handshake (SYN=1, seq=x) is sent

  • After the second handshake (SYN=1, ACK=1, SEq = Y, ACKnum=x+1) is sent, the server enters the SYN_RCVD state.

  • For the third handshake (ACK=1, ACKnum=y+1), the client enters the ESTABLISHED state after the packet is sent. When the server receives the packet, the client also enters the ESTABLISHED state. The TCP handshake is used to start data transmission.

Four waves:

  • After the first wave (FIN=1, SEq =a) is sent, the client enters the FIN_WAIT_1 state

  • After the second wave (ACK=1, ACKnum=a+1) is sent, the server enters the CLOSE_WAIT state, and the client enters the FIN_WAIT_2 state after receiving the acknowledgement packet

  • After the third wave (FIN=1, SEQ = B), the server enters the LAST_ACK state and waits for the last ACK from the client.

  • On the fourth wave (ACK=1, ACKnum=b+1), the client receives the shutdown request from the server, sends an acknowledgement packet, and enters the TIME_WAIT state, waiting for a fixed amount of time (two maximum lifetime, 2MSL, 2 Maximum Segment Lifetime); if the server does not receive an ACK from the server, the connection is CLOSED. After receiving the acknowledgement packet, the server closes the connection and enters the CLOSED state.

3. Flow chart of thread pool execution

Thread pool: A thread usage pattern. Too many lines will bring scheduling overhead, which will affect cache locality and overall performance.

Thread pools, on the other hand, maintain multiple threads, waiting for supervisors to assign tasks that can be executed concurrently, avoiding the cost of creating and destroying threads for short-duration tasks. Thread pool execution flows are a must for every development.

Execute the process

  • When a task is submitted and the number of surviving core threads in the thread pool is smaller than corePoolSize, the thread pool creates a core thread to handle the submitted task.

  • If the number of core threads in the thread pool is full, that is, if the number of threads is equal to corePoolSize, a newly submitted task will be queued to the workQueue for execution.

  • When the number of threads in the thread pool is equal to corePoolSize and the workQueue is full, determine whether the number of threads reaches maximumPoolSize, that is, whether the maximum number of threads is full. If not, create a non-core thread to execute the submitted task.

  • If the current number of threads reaches maximumPoolSize and a new task comes in, reject it.

The JDK provides four classes for handling rejection policies

  • AbortPolicy (throws an exception, default)

  • DiscardPolicy (Simply discard tasks)

  • DiscardOldestPolicy (Discarding the oldest task in the queue and recommitting the current task to the thread pool)

  • CallerRunsPolicy (to the thread from which the thread pool call is made for processing

4.JVM memory structure

The JVM memory structure is a foundation that Java programmers must master.Program counter (PC register)

A program counter is a small memory space that can be seen as a line number indicator of the bytecode being executed by the current thread.

In the virtual machine model, the bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to be executed. Branch, loop, exception handling, thread recovery and other basic functions need to be completed by the counter.

Java virtual machine stack

  • Like program counters, the Java virtual machine stack is thread-private and has the same lifetime as a thread

  • Each method execution creates a “stack frame” that stores information about local variables (including parameters), operand stacks, dynamic links, method exits, and so on. Each method is called to the end of the execution process, corresponding to a stack frame in the virtual machine stack from the stack to the stack process.

  • Local variable tables store basic data types Boolean, byte, CHAR, short, and so on

Local method stack

It is similar to the virtual machine stack except that the virtual machine stack serves Java methods executed by the virtual machine, while the Native method stack serves Native methods.

The Java heap

  • The GC heap is the largest area of memory managed by the Java Virtual Machine and is shared by individual threads and is created at JVM startup.

  • The size is set by -xms (minimum) and -xmx (maximum) parameters, where -xms is the minimum memory that the JVM can request at startup and -xmx is the maximum memory that the JVM can request.

  • Because collectors now use a generational collection algorithm, the heap is divided into Cenozoic and old. Cenozoic is composed of S0 and S1, and the size of Cenozoic can be specified by the -xMN parameter.

  • All object instances and arrays are allocated on the heap.

  • In addition to the Class version, field, method, interface, and other description information, the Class file contains the constant pool, which is used to store the various symbolic references generated by the compiler. This part of the content will be put into the runtime constant pool in the method area after the Class is loaded.

Methods area

  • Also known as “persistent generation”, it is used to store class information, constants, static variables loaded by the VIRTUAL machine, and is a memory area shared by each thread. You can limit the size of the method area with the -xx :PermSize and -xx :MaxPermSize arguments.

  • Runtime constant pool: The part of the method area where the bulk of the content comes from the JVM loading classes.

  • In addition to the Class version, field, method, interface, and other description information, the Class file contains the constant pool, which is used to store the various symbolic references generated by the compiler. This part of the content will be put into the runtime constant pool in the method area after the Class is loaded.

5.Java memory model


  • Java multithreading communicates through shared memory, and there are a series of problems such as visibility, atomicity, and sequence in the process of communication. JMM is a model built around multithreading communication and a series of features related to it.

    The JMM defines syntactic sets that map to the Java language as volatile, synchronized, and other keywords.

    Interested can look at my other note: www.jianshu.com/p/3c1691aed…

  • The Java memory model stipulates that all variables are stored in the main memory, and each thread has its own working memory. The working memory of the thread stores a copy of the main memory of the variables used in the thread. All operations on variables must be carried out in the working memory of the thread, instead of reading and writing the main memory directly.

    Different threads cannot directly access variables in each other’s working memory, and the transfer of variables between threads requires data synchronization between their own working memory and main memory.

6.SpringMVC execution flow chart

  • The User sends a request to the server, and the front-end control Servelt DispatcherServlet captures it.

  • The DispatcherServlet parses the request URL, calls HandlerMapping to retrieve all related objects configured by this Handler, and returns them as HandlerExecutionChain objects.

  • The DispatcherServlet selects an appropriate HandlerAdapter based on the Handler obtained.

  • Extract the model data from the Request, populate the Handler entry parameter, and start Handler (Controller)

  • When Handler completes execution, a ModelAndView object is returned to the DispatcherServlet

  • Based on the returned ModelAndView, select an appropriate ViewResolver

  • The ViewResolver combines Model and View to render the View

  • Render results are returned to the client.



7.JDBC execution process

JDBC execution process:

  • Connect to data source

  • Pass query and update instructions to the database

  • Process the database response and return the result

8. Spring Cloud component architecture

Spring Cloud is a Cloud native application development tool based on Spring Boot implementation. It provides an easy way to develop operations such as configuration management, service discovery, fuses, intelligent routing, micro proxy, control bus, distributed session, and cluster state management in jVM-based cloud native application development.

  • Eureka is responsible for registration and discovery of services.

  • Hystrix monitors calls between services, acting as a circuit breaker and downgrader.

  • Spring Cloud Config provides a unified configuration center service.

  • All outbound requests and services are forwarded through Zuul, acting as an API gateway

  • Finally, Sleuth+Zipkin was used to record all the request data for our subsequent analysis.

  • Spring Cloud Ribbon is a client load balancing tool based on Netflix Ribbon. It is a client load balancer based on HTTP and TCP.

  • Feign is a declarative Web Service client whose purpose is to make Web Service calls easier.

9. Dubbo calls

Dubbo is a distributed services framework that aims to provide high performance and transparent remote service invocation solutions. This is easily confused with load balancing, which provides a common address for external requests to be routed to different servers through polling, randomization, etc.

  • Provider: exposes the service Provider of the service.

  • Consumer: Service Consumer that invokes the remote service.

  • Registry: A Registry where services are registered and discovered.

  • Monitor: monitors The Times and time of service invocation.

  • Container: service running Container.



, END,

The growth path of programmers

Though the road is long, the journey is sure to come

This article was originally posted on the wechat public account of the same name “The Growth of programmers”, reply to “1024” you know, give a thumbs up.

Reply [520] to receive the best learning method for programmers

Reply to [256] for Java programmer growth plans