What exactly is EJB? Is it amazing ??

Source: Internet
Author: User
Tags object serialization

1. What is "service cluster "? What is "enterprise-level development "?
Now that EJB is for "service cluster" and "enterprise-level development", we have to talk about what is the so-called "service ".
Cluster "and" enterprise-level development!
In fact, this issue is quite critical, because J2EE is not clearly stated, and there are no detailed indicators or examples to tell
When does a large number of programs use ejbs. As a result, we all have some associations and think that EJB "Distributed Operation
"Server Load balancer" improves system execution efficiency. However, many people are expected to make a mistake. This "service cluster"
And "Distributed Computing" does not fundamentally solve the problem of load execution, especially for database application systems.
Why?
Let's repeat the EJB back to the original form for your analysis.


2. Broke the EJB folder.
Let's take a good look at the EJB concept and see what clues can be found.


3.1 analysis of the ejb Concept
Let's take a look at the official explanation of EJB:
The core of business software is its business logic. The business logic abstracts the entire business process and uses
The computer language implements them.
......
J2EE extracts the business logic from the client software and encapsulates it in a group.
. This component is executed on an independent server, and the client software calls the services provided by the component through the network to implement
The current business logic, while the client software is only responsible for sending call requests and displaying processing results. In J2EE,
This execution is performed on an independent server and the component that encapsulates the business logic is EJB (Enterprise Java
Bean) component.
In this case, we mainly focus on the following points:
Analysis 1: "business logic"
We have noticed that the EJB concept mainly refers to the encapsulation of "business logic", and this business logic is
What? In fact, this so-called "business logic" can be fully understood as a "class for executing a specific task.
".
Analysis 2: "extract business logic from client software and encapsulate it in components ...... Run in one server
Server"
Now that we know that the concept of "business logic" is the "class" for executing specific tasks, what is "Slave Client
Extracted from the software "? In fact, this is to put the "class" originally put in the client, out of the client, put
And put the component into a server for execution.
3.2 turn the concept of EJB into a vernacular
To put it bluntly, "Put the classes in the software you write that need to execute the specific tasks, not to the client software.
But pack it into a server ".
3.3 problems found
Whether it is in the "Eight shares" or in the white saying that this EJB concept has mentioned a word-"client software ".
"Client software "? Does EJB mean C/S software?
Yes, that's right!
EJB is to put those "classes" on a server, and use the C/S form of software client to "class" on the server.
Line call.
It's about to crash!
What is the relationship between EJB and JSP? EJB is related to JSP, but the relationship is really not very big, at most in JSP
The server calls the EJB class on the remote service.


4. 1. What is the bottom layer of EJB?
We have uncovered the true meaning of the EJB "Eight shares" concept, and then we will analyze the underlying implementation technology of EJB, through the underlying implementation
Current technology to analyze how EJB works.


4.2 Implementation Technology of EJB
EJB is a component executed on an independent server, and the client calls the EJB object through the network. In Java
RMI is the technology that can realize remote object calling, and the foundation of EJB technology is RMI. Using RMI technology, J2EE
When the EJB component is created as a remote object, the client can call the EJB object over the network.
4.3 let's see what RMI is.
Before speaking about RMI, you need to understand two terms:
Object serialization
Distributed Computing and RPC
Noun 1: Object serialization
Object serialization concept: the object serialization process is to convert the object state into word throttling and restore the object from the byte stream
Image. After the object state is converted into word throttling, it can be saved to the file using various byte stream classes in the Java. Io package,
You can also send the object data to another host through a network connection.
The above statement is a bit "Eight shares". We 'd better explain it in a vernacular: Object serialization is to implement
For example, you can customize a class myclass or convert any class object
Byte array, that is, it can be put into a byte array. At this time, since you have put an object into a byte
In the array, then of course you can handle it at will, the most used is to send it to the network for Remote Computing
On the machine. 2 11.


Term 2: distributed computing and RPC
RPC is not a pure Java concept. Since the concept of RPC was established before the birth of Java, RPC
Is the abbreviation of "Remote Procedure Call", that is, "remote process call ". Most programming languages before Java
Languages, such as Fortran, C, and COBOL, are procedural languages rather than object-oriented languages. Therefore
The language naturally uses a process to represent work, such as a function or subroutine, so that it can run on a machine on the network. Description
If it is white, a local computer calls a function on a remote computer.
2 12.


Term 3: the combination of the two is RMI
RMI stands for "Remote Method Invocation", and its Chinese name is "remote method call ".
The Java object serialization mechanism is used to implement distributed computing and realize the instantiation and calling of remote class objects.
To make it clearer, Object serialization is used to implement remote calls, that is, the combination of the above two concepts.
When this method is used to call a remote class, you do not need to write a socket program or sequence the object.
And can be called directly.
Remote method call is a mechanism in which objects in a computer call each other's functions and start processes of the other party.
The program syntax rules and
The syntax rules for method calls between objects on the local machine are the same.
2 13.

4.4 strengths
This mechanism brings great convenience to distributed computing system design and programming. Just follow the RMI rules to design the process
The network details under RMI, such as TCP and socket. Two computers at will
The communication between them is totally the responsibility of RMI. Calling objects on a remote computer is as convenient as a local object.
RMI can pass the complete object as the number of bytes and return value, not just the data type defined in advance. That's it.
It means that a complex type similar to a Java Hasse table can be passed as a number of partitions.
4.5 disadvantages
If it is a relatively simple method call, the running efficiency may be much slower than the local operation, even if
Compared with the applications returned by simple data of the mechanism, the reason is that the information to be transmitted between networks is not only
Including the return value of the function and the serialized bytes of the object.
4.6 EJB is based on RMI
Through RMI technology, J2EE creates the EJB component as a remote object. Despite using RMI technology, EJB only needs
To define remote interfaces without generating their implementation classes, some details in RMI technology are blocked.
However, in any case, the foundation of EJB is still RMI. Therefore, if you want to understand the principles of EJB, you only need
You just need to figure out the principles. You can also figure out when to use ejbs and when not to use ejbs.


5. The so-called "service cluster" in EJB"
Now that you know, RMI places various task and function classes on different servers, and then
The call rules established between the server are used to implement distributed operations. Therefore, the so-called "service cluster" concept of EJB is clearly defined.
It is to put the classes previously computed on one computer into other computers for execution, so as to share the operation
The CPU and memory resources required by these classes. At the same time, different software functional modules can also be placed in different
Server, you can directly change the classes on these servers when you need to modify some functions. After the changes, all the customers
The software of the user has been changed. 2 14.

 

6. is such a deployment impeccable?
Figure 2 14 shows that the "service cluster" seems "impeccable". In fact, this figure is not completely illustrated.
Complete the picture. Let's see if there is any problem.
6.1 bottleneck on the database
After careful observation, we found that such a configuration has a bottleneck, which we can see in 2 15.


Let's take a look at the structure diagram in Figure 2 15. Now we assume that we want to implement the query for the same database by each server
No matter how many functional servers you deploy, you must query one database server. That is to say,
No matter how "computing" is distributed ", you also need to retrieve data from a server. However, it seems that
The module is distributed on different servers to share the CPU resources of each master computer. However, the real bottleneck is not
Here, instead, the database server. The database server is very busy dealing with queries and operations on various servers.
Request.
Therefore, through this structure, we learned that EJB cannot completely solve the load problem.
It is not in the position of the function module, but in the database server.
6.2 what if the database is separated and data is shared?
Some readers will surely think of the following application structure, which can be seen in 2 16.


It is to deploy a database after each function server, so that it will not solve the problems mentioned in the previous section.
? Yes, it overcomes the database query load problem, but there is a new problem, that is, the "data sharing" problem.
It's not easy to conquer.
6.3 The network is facing great pressure, making your applications slow.
Let's move forward and look at the two networks in the architecture we see in. One is "Network A" and the other is "B ".
The two networks are different. "B network" is usually a LAN, and the bandwidth is generally 10 m/100 m, the speed is fast, so
Fortunately, however, "a network" is often the Internet or the use of telecom networks to interconnect the VPN network or WAN. "Network"
Bandwidth is generally narrow. For example, the bandwidth of the ADSL Network is only 512 K-2 m.
High, so generally there will be no higher bandwidth.
In this network, the data exchanged between the function module and the client software is run.
The advantage is bandwidth usage.
Therefore, how slow the execution speed of this application architecture can be imagined. It's not an exaggeration.
It's as slow as pulling a car.
A system such as Lao Niu:
A major company that is currently working as a carrier's network management system on the Chinese Internet, one of its early network management software is
The middleware uses this architecture as the C/S structure application system.
Once, I evaluated my application system and deployed it to a non-carrier large network.
In the middle of the year, we see the above description, the speed has reached an unbearable point, open a traffic diagram,
Sometimes it takes 15 minutes to complete the presentation. However, the system did not find this problem during development,
Why? Because they did not take into account the complexity of the actual user connection network of the application, thus causing greater problems for the company
This development architecture was finally abandoned due to a huge loss.


7. EJB is available for live use, and J2EE is not required to use EJB
Through the above section, it seems that the relationship between EJB and the B/S structure of Web application development is not great. In fact
Otherwise. Assume that the "client program" is understood as a server, which can also be applied,
If the server calls ejbs from each other, there is no wan bandwidth limit.
However, in the following cases, try not to use EJB:
1. Relatively simple pure web application development, no need to use EJB.
2. Applications that need to be used together with other service programs, but the network protocol defined by the call or return can be solved
You do not need to use EJB.
3. applications with a C/S structure that are frequently asked by others should not use EJB whenever possible.

 

 

Summary:

A. EJB implementation principle: Put the code originally implemented by the client on the server side and communicate with each other through RMI.

B. RMI implementation principle: distributed computing is implemented through Java object serialization mechanism.

C. server cluster: connects servers of different functional modules through RMI communication to implement a complete function.

 

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.