Java Knowledge Summary-26

Source: Internet
Author: User
Tags connection pooling

Tag:pat    decision     Permanent     static    loader    observer    dependency     default    interface   

Transaction:
A transaction is a minimal unit of work that works as a whole, whether successful or not.
A sequence of operations performed by a single logical unit of work that is either completely executed or completely not executed.
When a transaction fails, the system returns to the state before the transaction started. This process of canceling all changes is called "rollback" (rollback). For example, if a transaction successfully updated two tables and failed to update the third table, the system reverts to the original state for two updates and returns.
Role:
Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully. By combining a set of related actions into a single unit that either succeeds or all fails, you can simplify error recovery and make your application more reliable.
------
A logical unit of work to be a transaction must be full-
Perform transactions in an isolated state so that they appear to be the only operations that the system performs within a given time. If there are two transactions that run at the same time and perform the same function, the isolation of the transaction will ensure that every transaction in the system considers only that the transaction is in use by the system.
Dirty read virtual read non-repeatable read
4. Persistence
Persistence means that any changes that occur in the system will be permanent once the transaction is executed successfully. There should be some checkpoints to prevent loss of information if the system fails. Even if the hardware itself fails, the state of the system can still be rebuilt by the task of recording the transaction completed in the log. The concept of persistence allows the developer to assume that the completed transaction is a permanent part of the system regardless of what has changed in the future.
Isolation level
READ UNCOMMITTED (READ UNCOMMITTED content)---at that isolation level, all transactions can see the execution results of other uncommitted transactions. Both dirty reads dirty read
Read Committed (reads the submission)---it satisfies the simple definition of isolation: A transaction can only see changes that have been submitted to the firm. Not repeatable read (Nonrepeatable Read)
Repeatable Read (reread) The default transaction isolation level of MySQL, which ensures that multiple instances of the same transaction will see the same rows of data while concurrently reading the data. can cause Phantom reads (Phantom read)
Serializable (serializable) The highest isolation level, which resolves a phantom reading problem by forcing transactions to sort, making it impossible to collide with each other


Factory mode:
belongs to the Create pattern, which provides the best way to create an object. The specific implementation of shielding products, the caller only care about the interface of the product
-----------
In Factory mode, we create the object without exposing the creation logic to the client, and by using a common interface to point to the newly created object. Defines an interface that creates an object, letting its subclasses decide which factory class to instantiate, and the factory pattern to defer its creation to subclasses
----------
Advantages:
1. A caller wants to create an object, as long as it knows its name.
2, high scalability, if you want to add a product, as long as the expansion of a factory class can be.
3, the specific implementation of shielding products, the caller only care about the interface of the product.
Disadvantages:
Each time you add a product, you need to add a specific class and object implementation of the factory, so that the number of classes in the system multiplied, to a certain extent, increase the complexity of the system, but also increase the system specific class dependency. That's not a good thing.
-----------
Implementation: The third-party factory class is responsible for creating objects calling the factory class to get the object created
Simple factory: No matter how many products, factory class on one (factory only need to provide a static method) so the simple factory is also called Static factory (in the product class in accordance with the open and closed principle, the factory class does not meet the opening and shutting principle)


Factory method Mode:
Implementation: The factory interface of the factory is created to implement the plant class specific class call to create a factory factory class to create a factory by creating a factory by the method of the To object
--Defining an interface for a factory class all collective plants produce one product

Single-Case mode:
Involves a single class that is responsible for creating its own objects, while ensuring that only a single object is created. This class provides a way to access its only object, which must be a static method, and can be accessed directly without instantiating an object of that class.
Implementation: Private property of the constructor private properties public static method of getting this class object


Interface-Oriented Programming:
Interface is a specification, a rule-oriented interface programming refers to the implementation of interfaces and the use of interfaces to the interface as the central implementation of the same interface as a medium for both to connect the interface as a means of the third party to reduce the coupling between the two so that any one party changes without affecting the other party's internal logic Facilitates the division of software and unit testing of modules

Concept of package:
The work of the same development team is done in one package, and different packages often represent different development teams.

Data Source:
The data source, as its name implies, is the source of the data, the device or the original media that provides some of the required data. All information that establishes a database connection is stored in the data source. Just as you can find a file in the file system by specifying a file name, you can find the appropriate database connection by providing the correct data source name.

Lightweight and heavyweight:
---------------
Lightweight means that its creation and destruction do not need to consume too much resources, which means that the session object can be created and destroyed frequently in the program;
Lightweight does not need to inherit or implement any interface of any class, is not intrusive, uses pojo development
Lightweight, which focuses on reducing the complexity of development, the corresponding processing power is weakened (such as a weak transaction, no distributed processing power), and is more suitable for small and medium enterprise applications.
Lightweight, no dependencies on containers, easy to configure, easy to use, and short start-up times
*************
Heavyweight heavyweight means that it is not possible to create and destroy instances of it at will, and it consumes a lot of resources.
Heavyweight needs to inherit or implement classes or interfaces in the framework, strong dependencies, intrusive
Heavyweight emphasis on high scalability, suitable for the development of large-scale enterprise applications.
Heavy-weight dependence on the container. , provides a fixed set of functions, does not have the ability to configure. , different products, the deployment process is different, not easy to general. , and the startup time is long.

Java memory leaks
Memory leaks refer to useless objects (objects that are no longer being used) that persist in memory or the memory of useless objects is not released in a timely manner, resulting in a waste of memory space known as memory leaks. Memory leaks are sometimes not critical and imperceptible, so developers do not know that there is a memory leak, but sometimes it can be very serious and will prompt you out of your memory.
When did-----happen-------
A memory leak occurs when a long-period variable references a short-period object


Connection pool:
Connection pooling is the technique of creating and managing a pooled pool of connections that are ready to be used by any thread that needs them.
Advantages:
Reduce connection creation time
Simplified programming model
Controlled use of resources

JavaBean definition:
Private properties
Geter Seter Method
Non-parametric construction

Development principles:
----------
Open and close principle: for extended development to modify the closed (extension function is recommended and easy to expand, not allowed to modify the original methods and properties-that is, after the expansion of the original "object" can not have an impact)

Decoration Mode:
1. Do not change the original class on the basis of all the functional properties of the operation (the original class as a property, the method of constructing the original class--get,set methods is to call the original class property assignment to the Class property, if the change in the method class after the set assignment operation)
2. Can be decorated repeatedly
------
Implementation: Decoration class inheritance is decorated class
The adornment class has a decorated class of objects as its members
Decoration class passing in a decorated class object through a parameter structure
The adornment class overrides all the hair methods of the decorated class, overriding the corresponding method of the adorned object
For methods that need to be decorated, add the appropriate adornment code before or after the call to use the method
Decoration class can be overridden by the method of the decorated class, but also the first own method
---
Decoration of the class can be decorated once again (effect overlay) Be sure to call the original object method
Characteristics:
Each decorative object needs to pass in a decorative object
Each decoration class can be used multiple times


Dynamic Agent
JDK Dynamic Agent:
Define an interface
The proxy class implements a method-aware interface (non-tagged interface) and is defined in the interface by the proxy method
Write a proxy class implementation Invocationhandler interface override invoke method parameter list (instance of proxy class, method called, parameters of called method)
The argument list is an instance of the class loader of the proxy class that implements the interface proxy class
How a = (Show) proxy.newproxyinstance (User.class.getClassLoader (), User.class.getInterfaces (), New Jdkproxyuser ());
----------------------
Cglib Agent


Viewer mode:
The Observer pattern (Observer pattern) is used when there is a one-to-many relationship between objects. For example, when an object is modified, its dependent objects are automatically notified. The observer pattern belongs to the behavioral pattern.
-------
Advantages: 1, the observer and the observer are abstract coupled. 2, set up a set of trigger mechanism.
Cons: If an Observer object has a lot of direct and indirect observers, all observers are notified to spend a lot of time
With cyclic dependencies, observing the target triggers a cyclic call between them, which could cause the system to crash
The observer pattern does not have a mechanism for the viewer to know how the target object is changing, but only to know that the observation target has changed.


For a decorated object, you can have different knowledge of it.
Advantages:
Advantages: Decorative and decorative categories can be independent development, not mutual coupling, decoration mode is an alternative mode of inheritance, decoration mode can dynamically extend the function of an implementation class


The difference between static agent and decoration mode;
1) Static Proxy: The proxy class does not need to inherit the proxy class, adornment mode: The adornment class must inherit the inheriting class
2) static proxy and decorative mode all require a member variable to hold a Target class object;
3) Static proxy: The target class object can be passed in by a parameter constructor, or it can be created in the parameterless constructor, adornment mode: The target class must pass through a parameter construct to pass in
4) Both static proxy and adornment mode must implement/override all methods of the target class
5) Static agents can invoke or not invoke the corresponding method of the original object when implementing these methods; Adornment mode must call the original method
6) Static proxy implementation of these methods, generally there is no new method, decorative mode is not necessarily

Proxy mode:
Static Proxy Disadvantage: If there are many methods of proxy classes and few methods need to be modified, a lot of code repeats
------------
In proxy pattern, one class represents the functionality of another class. This type of design pattern belongs to the structural pattern.
In proxy mode, we create an object with an existing object to provide a functional interface to the outside world.
*******
The proxy class holds a proxy object with a member variable
The Proxied object can be passed in through a parameter constructor, or it can be created in a parameterless constructor (--different from adornment mode)
The proxy class implements the desired method of the proxy class,
In the method implementation, you can invoke the corresponding method of the proxy object, add the new business code, or you can not call (different from the adornment mode)
In addition to the method of implementing the proxy class, the proxy class generally does not increase the method

Annotations:
The prototype of annotation is the introduction of annotations as an extension of annotations into a grammatical element, which in itself is intended to supplement the annotated programming elements to further refine the logical semantics of the programming elements.

DI Dependency Injection


IOC control reversal

Java Knowledge Summary-26

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.