跳到主要內容

發表文章

目前顯示的是有「advanced」標籤的文章

Distributed transactions

Table of contents [ hide ] Basic theory  CAP States that any distributed data store can provide only two of the following three guarantees. Consistency Every read receives the most recent write or an error. Availability Every request receives a (non-error) response, without the guarantee that it contains the most recent write. Partition tolerance The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes. Typical architecture of distributed systems When a network partition failure happens, it must be decided  whether to do one of the following: CP: cancel the operation and thus decrease the availability but ensure consistency AP: proceed with the operation and thus provide availability but risk inconsistency. BASE Basically-available, soft-state, eventual consistency. Base theory is the practical application of CAP theory, that is, under the premise of the existence of partitions and copies, through certain syste

Concurrency

Table of contents [ hide ] Glossary Synchronous:   When you start a program, you must wait until it finishes before moving on to the next step. Asynchronous: When you start a program, it returns immediately and runs the program in the background, and you can move on to the next step. Concurrency: Concurrency is the ability of different parts or units of a program, algorithm, or problem to be executed out-of-order or in the partial order, without affecting the final outcome Parallelism: Parallel computing is a type of computation in which many calculations or processes are carried out simultaneously. Blocking: A process that is blocked is one that is waiting for some event, such as a resource becoming available or the completion of an I/O operation Non-blocking: An algorithm is called non-blocking if the failure or suspension of any thread cannot cause the failure or suspension of another thread Concurrency level Blocking: A thread is blocked and it cannot execute until other threa

Annotation

Table of contents [ hide ] Design pattern Annotations are an implementation of the decorator design pattern. The decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class. Annotations in Java Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate. Annotations have a number of uses: Information for the compiler:  Annotations can be used by the compiler to detect errors or suppress warnings Compile-time and deployment-time processing:  Software tools can process annotation information to generate code, XML files, and so forth. Runtime processing:   Some annotations are available to be examined at runtime. Annotations in Spring Spring uses annotations extensively as a core feature, especially Spring AOP, and almost all the functions we use in S

Reflection

Reflection is an API that is used to examine or modify the behavior of methods, classes, and interfaces at runtime. Reflection is the basis for many advanced features such as annotations, and dynamic proxies. Many frameworks use reflection to implement functions, such as Spring IOC and AOP, ORM mapping frameworks, etc. Pros: Inspection of interfaces, classes, methods, and fields during runtime is possible. Arbitrary calls to methods and properties of objects. Create an instance arbitrarily. Cons: Reflective code is less readable and maintainable. Performance overhead. Break the principle of encapsulation. Example: Abstract factories with reflection can reduce redundant code to keep clean code. see Proxy . reference: https://www.geeksforgeeks.org/reflection-in-java/ https://www.javatpoint.com/java-reflection https://github.com/hollischuang/toBeTopJavaer

Proxy

Table of contents [ hide ] Proxy in design pattern The proxy pattern is a software design pattern, as a wrapper or agent object that is being called by the client to access the real serving object behind the scene. There are two advantages: Provides access control for real objects. Provides additional functionality when accessing real objects. And there are two types of proxy: Static proxy: proxies are created manually. Java example on  GitHub . Dynamic proxy: proxies are created by JDK Proxy or CGLib Proxy with reflection. JDK proxy Before the proxy object is created, it must implement the invoke method of the InvocationHandler, which is invasive to the target object. JDK Dynamic proxy can only proxy by the interface (so your target class needs to implement an interface, which is then also implemented by the proxy class) CGLib proxy The proxy object is created by implementing the intercept method of MethodInterceptor, and the target object does not need to implement this metho