What exactly is EJB? Is it so mysterious ??

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!
This problem is actually critical, because J2EE
Is not described in, there are no specific indicators or examples to tell
When do programmers use ejbs?
When not required. As a result, we all come up with some associations and think that EJB "Distributed Operation
"Server Load balancer" improves system operation efficiency. However, it is estimated that many people make a mistake. This "service cluster"
And "Distributed Computing" does not fundamentally solve the problem of Running Load, especially for database application systems.
Why?
First, we need
Let's take a look at it.

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 EJB.
Official explanation:
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
The solution to this problem is to extract the business logic from the client software and encapsulate it in a group.
. This component runs 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
Medium,
The component that runs on an independent server and encapsulates the business logic is
Java
Bean) component.
Here we mainly focus on the following points:

Analysis 1: "business logic"

We noticed that
Is the encapsulation of "business logic", and the 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 on the client, out of the client, put
To a component and put it on a server for running.

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 Paper, this EJB concept has mentioned the 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 call the "classes" on the server using a software client in the form of C/S. 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, it is to call the EJB class on the remote service on the JSP server side.

4. 1 What is the bottom layer of EJB?

We have uncovered the true meaning of the EJB "Eight shares" concept. Then we will analyze the underlying implementation technology of EJB and analyze the working method of EJB through the underlying implementation technology.

4.2 Implementation Technology of EJB

EJB is a component running 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, while RMI is the basis of EJB technology. Through RMI technology, J2EE creates the EJB component as a remote object, and the client can call the EJB object over the network. 4.3 let's see what RMI is. before talking about RMI, we 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. After the object state is converted to word throttling, you can use various byte stream classes in the Java. Io package to save it to a file, or send the object data to another host through a network connection. The above statement is a bit "Eight shares". We may explain in the vernacular that object serialization refers to the object of a class that is practically implemented in your program. For example, if 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, since you have put an object in a byte array, of course you can handle it at will. The most commonly used is to send it to a remote computing machine on the network.

2 11.

Term 2: distributed computing and RPC

RPC is not a pure Java concept, because before Java was born, RPC was already in place.
Yes "Remote Procedure
Call is short for "remote process call ". Most programming languages before Java
Language, such as Fortran, C, and COBOL
And so on, they are all procedural languages, not object-oriented. Therefore
The language naturally uses a process to represent work, such as a function or subroutine, so that it can be executed on another 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 ".
Java
The object serialization mechanism implements distributed computing to instantiate remote class objects and call methods.
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
The program does not need to sequence objects.
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 advantages this mechanism brings great convenience to distributed computing system design and programming. As long as you follow the RMI rules to design the procedure, you do not have to worry about the network details under RMI, such as TCP and socket. The communication between any two computers is solely the responsibility of RMI. Calling objects on a remote computer is as convenient as a local object. RMI can pass complete objects as parameters and return values, not just pre-defined data types. That is to say, you can pass complex types like Java Hasse tables as a parameter. 4.5 disadvantages
If it is a relatively simple method call, its execution efficiency may be much slower than local execution, even if it is slower than the application returned by the simple data of the remote socket mechanism, because, the information to be transmitted between networks not only includes the return value information of the function, but also the serialized bytes of the object. 4.6 EJB uses RMI-based RMI technology. J2EE creates EJB components as remote objects. Although EJB uses RMI technology, however, you only need to define remote interfaces without generating their implementation classes, which shields some details of RMI technology. However, in any case, the foundation of EJB is still RMI. If you want to understand the principles of EJB, you just need to clarify the principles of RMI. You can also figure out when to use EJB and when not to use EJB.

5. now that the so-called "service cluster" in EJB is known, RMI places various tasks and functional classes on different servers, then, distributed computation is implemented through the call rules established between various Server servers, so that the so-called "service cluster" concept of EJB is understood. It is to put the classes previously computed on one computer into other computers for running, so as to share the CPU and memory resources required for these classes. At the same time, you can also place different software function modules on different servers. You can directly modify the classes on these servers when you need to modify some features, after the modification, all client software is modified. 2 14.

 

6. is this deployment a "service cluster" shown in Figure 2 14 seemingly "impeccable"? In fact, this figure is not completely complete. Let's complete this picture, let's see if there is any problem. 6.1 bottleneck after careful observation on the Database End, it is found that this configuration has a bottleneck, as shown in.

Let's take a look at the structure diagram in Figure 2 15. If you want to query the same database for each server, no matter how many functional servers you deploy, you must query a database server. That is to say, no matter how "distributed" your "computing" is, you also need to retrieve data from a server. Although it seems that the power modules are distributed on different servers to share the CPU resources of each master computer, the real bottleneck is not here, but the database server. The database server is very busy with queries and operation requests from various servers. Therefore, through this structure, we learned that EJB cannot completely solve the load problem, because the bottleneck is not in the position of the functional 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, as shown in Figure 2 16.

 
It is to deploy a database after each functional server. Does this solve the problem mentioned in the previous section? Yes, it solves the problem of database query load, but there is a new problem, that is, the problem of "data sharing" is not easy to solve.

6.3 The network is facing great pressure, making your applications slow.

Let's look forward to seeing that there are two networks in this architecture, as shown in Figure 2 15,

One is "Network A" and the other is "Network B". The two networks are different. "B network" is often a LAN, and the bandwidth is generally 10 m/100 m, the speed is fast, so it is better to say,

However, "a network" is often the Internet or the use of the telecom network to interconnect the VPN network or WAN. Network A is characterized by a narrow bandwidth. For example, the ADSL Network only has a bandwidth of 512 KB-2 MB,

Because Wan interconnection costs are high, there is usually no higher bandwidth. In this network, the data exchanged between the function module and the client software is run, and the data occupies a lot of bandwidth. Therefore, the running speed of this application architecture is quite slow. It's not an exaggeration to say that it's a little slow to get rid of a car.

A system such as Lao Niu:

At present, a large company that is working as a carrier network management system on the Internet in China, one of its early network management software is an application system that adopts the C/S structure based on this architecture.

Once, when I evaluated my application system as an evaluator and deployed it on a non-operator large network, we described it as follows,

The speed has reached an intolerable level. Opening a traffic diagram sometimes takes 15 minutes to complete. 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, which caused great losses to the company, the development architecture was eventually abandoned.

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 big, but it is actually not. If we understand the "client program" as a server, this can also be applied,

In addition, if the server calls ejbs to each other, there will be no wan bandwidth restrictions. However, try not to use EJB in the following situations:

1. Relatively simple pure web application development without using ejbs.

2. Applications that need to be used together with other service programs, but applications that can be resolved by calling or returning custom network protocols do not need to use ejbs.

3. Do not use EJB for C/S-structured applications that are frequently accessed.

 

Summary:

A. EJB implementation principle: Put the code originally implemented on the client side to the server side, and rely on RMI for communication.

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.

This article is reproduced in http://blog.csdn.net/jojo52013145/article/details/5783677

 

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.