Why is the J2EE container and J2EE application? --discuss

xiaoxiao2021-04-07  386

Why is the J2EE container and J2EE application?

We know that J2EE application is only available in the J2EE container to run, then why is it divided into J2EE container and J2EE application? By transporting J2EE container

Analysis of the row mechanism, we can find that the J2EE container has separated some general functions of the general application system, such as transaction mechanism, security mechanism, and performance optimization mechanisms such as object pool or thread pool.

These functional mechanisms are almost required for each application, so they can be separated from the specific application system to form a universal framework platform, and the design development of these functional mechanisms has a certain difficulty, while operating stability and rapidity. It is very important to accumulate long debugging and running experience, thereby forming a special J2EE container server product such as Tomcat JBoss, WebSphere, WebLogic, etc.

From the J2EE system, it is divided into two aspects of J2EE containers and J2EE applications, and we have seen a Separation Of Concerns.

Disperse

Separate general demand functions from irrelevant classes; at the same time, many classes can share a behavior, once the behavior changes, there is no need to modify many classes, as long as this behavior can be modified.

AOP is this programming method that realizes dispersion, it will "pay attention" into "aspect".

What is AOP?

AOP is OOP continuation, is an abbreviation of Aspect oriented Programming, meaning

Programming in terms of aspect. AOP is actually a continuation of GOF design patterns. The design pattern is tired and pursuing is the decoupper between the caller and the caller, and AOP can be said to be an implementation of this goal.

Example: Suppose there is a shared data must be simultaneously accessed by concurrent data, first, in the data object, called Data Class, and there will be multiple access classes, specifically used for Access this same data object at the same time.

In order to complete the function of the same resource above, you need to introduce the concept of lock Lock, that is, at a moment, when there is an access class to access this data object, this data object must be locked Locked, immediately after it is used

Unlock unlocked and access to other access classes.

Use traditional programming habits, we will create one

Abstract class, all access classes inherit this abstract parent class, as follows:

Abstract Class Worker {Abstract Void Locked (); Abstract Void AccessDataObject (); Abstract void unlocked ();

Disadvantages:

The AccessDataObject () method requires related code such as "lock" status. Java only provides a single inheritance, so the specific access class can only inherit this parent class. If the specific access class also inherits other parent classes, such as another parent class such as Worker, will not be able to implement. Reuse is discounted, the specific access class is only reused in the relevant "lock", which can only be reused in the case where the "lock" is also reused.

Carefully study the "lock" of this application, but there is actuality:

The "lock" function is not a primary or primary function of the specific access class, and the access class main function is to access data objects, such as reading data or changing actions.

"Lock" behavior is actually independent and distinguishing between the main functions of the specific access class.

The "lock" function is actually a longitudinal section of this system involving many classes, many ways. As shown below:

Therefore, a new program structure should be the longitudinal section of the system, such as the "lock" function of this application, this new program structure is aspect (aspect) in this application, "lock" (aspect) should have the following duties : Provide some must-have functions, implement the visited object

Unlock or unlock the function. To ensure that all Lock () locks can be called before the operation of modifying the data object, the unlock () unlocked after it is used.

Is AOP necessary?

Of course, the above application examples are also solved without using AOP, such as JBoss 3.xxx, also provides the above application functions, but does not use AOP.

However, using AOP allows us to understand software systems from a higher abstract concept, and AOP may provide a valuable tool. It can be said: Because the AOP structure is used, the source code of JBoss 4.0 is more likely to understand than JBoss 3.x, which is very important for a large complex system.

From another aspect, it seems that all people need to care about AOP, which may be a selection of architectural design. If the J2EE system is selected, the above general aspects of AOP have been implemented by the J2EE container, J2EE application system developer It may be necessary to pay more attention to the industry application aspect.

AOP specific implementation

AOP is a concept that does not set the implementation of the specific language, which overcomes the shortcomings of only single inheritance characteristics (such as Java), and the current AOP has the following items:

AspectJ (TM): Created in Xerox Parc. There are nearly ten years of history, technology maturation.

Disadvantages: too complicated; destroying packages; need special Java compiler.

Dynamic AOP: Use JDK dynamic proxy API or bytecode bytecode processing technology.

The specific items based on the dynamic agent API are:

JBoss 4.0 JBoss 4.0 Server

Bytecode-based projects are:

Aspectwerkz

Spring

转载请注明原文地址:https://www.9cbs.com/read-132536.html

New Post(0)