What is EJB?

Source: Internet
Author: User
Tags object serialization

1. We cannot help but ask what is a "service cluster"? What is "enterprise-level development"?
Since EJB is meant for "service clusters" and "enterprise-level development", it must be said that what is called "service
Cluster "and" Enterprise-level development "!
This question is actually very important, because there is no white in the Java EE, there is no specific indicators or examples to tell
When do the vast numbers of programmers use EJBS? So we all have some associations that the EJB "distributed operation
"Load balancing" increases the operational efficiency of the system. However, it is estimated that a lot of people are mistaken, this "service cluster"
and "distributed operations" do not solve the problem of running load at all, especially the application system for database.
Why?
Let's take the EJB back to the prototype and analyze it slowly.


2. Break the EJB and crush it .
Let's make a good analysis of the EJB concept and see what clues we can find.


3.1 EJB concept analysis
Let's take a look at the official explanation of EJB:
The core part of business software is its business logic. The business logic abstracts the process of the entire business process and implements them using the
computer-counting language.
... The
Java EE approach to this problem is to extract the business logic from the client software and encapsulate it in a group of
pieces. This component runs on a separate server, and the client software provides real
current business logic through the services provided by the network invoke component, and the client software is simply responsible for sending the call request and displaying the processing results. In the Java EE,
the component that runs on a separate server and encapsulates the business logic is the EJB (Enterprise Java
Bean) component.
Here we mainly focus on these points, we will analyze each:
Anatomy 1: The so-called: "Business logic"  
We notice that the EJB The concept of "business logic," the main reference is the encapsulation, and this business logic in the end what is
? So poised, in fact, this so-called "business logic" we can fully understand to perform a specific task "class
".
Anatomy 2: The so-called: "Extract the business logic from the client software, encapsulated in the component ... Run on a
server "
since we know that the concept of" business logic "is the" class "that performs a particular task, what is called" extracting from the client
Software "? In fact, this is the original put on the client's "class", take it out to the client, put
into a component, and put this component on a server to run.
3.2 The concept of EJB into plain English  
becomes plain English, "The class of software you write that needs to be executed, not on the client soft
on the piece, instead of giving him a packet and putting it on a server. "
3.3 found a problem  
Whether it's "stereotyped writing" or "plain English," The EJB concept mentions a word-"client software".
"Client Software"? Does the concept of EJB say C/s software?
Yes, that's right!
EJB is to put those "classes" on a server, in the form of C/S software client to the "class" on the server to the "Incoming
line" call. The
is going to crash!
What is the relationship between EJB and JSP? EJB and JSP are related, but the relationship is not very large, at most the
server side of the JSP call the remote service EJB class, that's all.


4   .1 What is the bottom of the EJB  
We uncover the true meaning of the EJB "stereotyped" concept, Then it analyzes the underlying implementation technology of EJB, and analyzes the working mode of EJB through the underlying real
technique.


4.2 EJB Implementation technology
EJB is a component that runs on a stand-alone server, and the client invokes the EJB object over the network. In Java
, the technology that enables remote object invocation is RMI, and EJB technology is based on RMI. With RMI technology, the Java EE
creates the EJB component as a remote object, and the client can invoke the EJB object over the network.
4.3 See what RMI is  
Before you say RMI, you need to understand two nouns:
serialization of objects
distributed computing and RPC
 
Object Serialization concept: The serialization of an object is the process of converting an object's state into a byte stream and recovering a pair of bytes from a byte stream
image. After you convert the object state to a byte stream, you can save it to a file with the various byte stream classes in the Java.io package,
or send the object data to another host over a network connection.
The above is a bit "stereotyped", we might as well explain in the vernacular: object serialization is the real
of your program to instantiate a class object, for example, you customize a class MyClass, or any class object, convert it to a
byte array, That is, you can put it in a byte array, now that you have put an object in the byte
array, then you can certainly dispose of it, the most used is to send him to the network on the remote Computing
machine. shown in 2 11.

 
 
RPC is not a purely Java concept, because the concept of RPC is already in existence before Java was born, and RPC
is the abbreviation for "Remote Procedure call", which is called "remoting procedure calls". Most of the programming languages before Java
, such as Fortran, C, COBOL, and so on, are procedural language, not object-oriented. As a result, these
programming languages naturally use procedures to represent work, such as functions or subroutines, that are executed on another machine on the network. When you say
White, the local computer calls a function on the remote computer. As shown in
2 12.

 
  The English name of the
RMI is "remote Method invocation", which is called "Remoting methods call", it is the use of Java object serialization mechanism to implement distributed computing, the realization of the remote class object instantiation and the method of invocation.
said more clearly, is the use of object serialization to achieve remote invocation, that is, the combination of the above two concepts, the use of
this method to invoke the remote class, there is no need to write the socket program, and do not need to sequence the object
operation, the direct call on the line is very convenient. A
Remote method call is a mechanism by which objects between computers invoke each other's functions to initiate a process, using this
mechanism, the program syntax rules used by objects on a computer when calling methods on another computer, and the
The syntax rules for method calls between objects on the local machine are the same. As shown in
2 13.

4.4 advantages
This mechanism gives a system design for distributed computing , programming has brought great convenience. As long as you follow the RMI rules design process
Order, you can no longer have to ask about the network details under RMI, such as: TCP and sockets, and so on. The communication between any two computers
is solely the responsibility of RMI. Invoking objects on a remote computer is as convenient as a local object.
RMI can pass complete objects as parameters and return values, not just predefined data types. Also
is that a complex type like Java Hassi can be passed as a parameter.
4.5 disadvantage  
If it is a simpler method call, its execution might be much slower than local execution, even if the remote socket
The simple data returned by the mechanism is slower than the application, because the information it needs to pass across the network is not only
contains the function's return value information, but also contains the byte content after the object is serialized.
4.6 EJB is RMI-based
with RMI technology, the EJB component is created as a remote object by the Java EE, and EJB uses RMI technology, but only
to define remote interfaces without generating their implementation classes, which masks some of the details of RMI technology.
But anyway, the basis of EJB is still RMI, so if you want to understand the principle of EJB, just make sure the RMI
principle is clear. You can also figure out when to use EJBS when you don't need ejbs.


5. The so-called "service Cluster" in EJBs
Now that we know, RMI is to put a variety of tasks and functions of the class on different servers, and then through the various services
The call rules established between the services implement distributed operations and understand the concept of EJB's so-called "service Cluster".
is to put a few classes that were originally on a computer and run it on another computer to share the
The CPU and memory resources that these classes need to occupy. At the same time, different software function modules can be put into different
On the server, when you need to modify some features, you can modify the class on these servers directly, modify all the guest
The client software has been modified. shown in 2 14.

6.  This deployment is impeccable  
the "service cluster" as shown in Figure 2 14 looks "invulnerable", in fact, it is not a picture of the complete, we come to
this picture complete, and then to see what the problem is not.
6.1 bottleneck on the database side  
After careful observation, it is found that there are bottlenecks in this configuration, as shown in 2 15.

 
Let's take a look at the structure of Figure 2 15, and now if you want to implement each server's query against the same database, then
Span style= "font-size:14px" > No matter how many feature servers you deploy, you need to do a query against a database server. That is,
no matter how "distributed" Your calculations are, you also need to get data from a single server. Although, it seems that the various functions of the
can be distributed on different servers to share the CPU resources of each host computer, however, the real bottleneck is not
here, but the database server there. The database server is very busy responding to queries from individual servers and operating
for requests.
As a result, this structure allows us to understand that EJB does not completely solve the load problem because the bottleneck
is not at the location of the function module, but on the database server.
6.2 if separate database, data sharing what to do  
Some readers will certainly think of the following application structure, shown in 2 16.

 
is to deploy each feature server behind a database, so that it does not solve the problem mentioned in the previous section
? Yes, it solves the problem of database query load, but there are new problems, that is, the problem of "data sharing" is
not easy to solve.
6.3 Network is under great pressure to make your application slow as the old cow
let's go ahead and look at the 2 15 shows that there are two networks in this architecture, one is "a net" one is "B
NET, these two networks are different. "B Network" is often a local area network, the general bandwidth is 10m/100m, faster, so the
to fortunately say, however, "A network" is often the Internet or the use of telecommunications network interconnection VPN network or called WAN. "A Network"
is characterized by a narrow bandwidth, such as ADSL network only has 512k-2m bandwidth, because the WAN interconnect cost is higher than
, so there is generally no higher bandwidth.
What runs on this network is the data exchanged between the function module and the client software, and this part of the data exactly
advantage is very bandwidth-intensive.
As a result, the application architecture can see how slow it is to run. Say a word is not exaggerated, a little think old cow
pull broken car as slow.
A system such as the old cow:
Currently in the Chinese Internet as a carrier network management system of a large company, its early management software is the
use of this architecture to do the C/s structure of the application system.
once, as an evaluator, I evaluated the application system and deployed it to a non-carrier-large network
, the situation described above has come to an intolerable level, opening a traffic graph, and
sometimes takes 15 minutes to render intact. However, the system did not find this problem in the development phase,
Why? Because they did not take into account the complexity of the actual user-connected network of the application, thus causing the company a greater
loss, so that the development architecture was eventually abandoned.


7. EJB Ingenious, the Java EE is not required to use EJB
It seems that the system relationship between EJB and the B/s structure of the Web application is not very large, as explained in the above section, in fact
Or else. If we understand the "client program" as a server, it can also be applied, and,
If the server makes EJB calls to each other, there is no question of WAN bandwidth throttling.
However, do not use EJBS as much as possible:
1, simple Web application development, do not need to use EJB.
2. Applications that need to be used in conjunction with other service programs, but the call or return of a custom network protocol can be resolved
Applications that do not require the use of EJBS.
3, more people concurrent access to the C/s structure of the application, try not to use EJB.

Summarize:

A.EJB Implementation principle: is to put the original client implementation of the code on the server side, and rely on RMI to communicate.

B.rmi Implementation Principle : It is through the Java object Serializable mechanism to achieve the distribution of computing.

C. server cluster: It is through RMI communication, connect the server of different function module, in order to realize a complete function.




http://blog.csdn.net/jojo52013145/article/details/5783677

What is EJB?

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.