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 quite critical, because J2EE is not described in the white, and there are no specific indicators or examples to tell
When does a large number of programmers use ejbs. 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?
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 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,
The component that runs on an independent server and encapsulates the business logic is EJB (Enterprise Java
Bean) component.
Here 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 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 use the C/S form of the software client
Line call.
It's about to crash!
What is the relationship between EJB and JSP? EJB has a relationship with JSP, but the relationship is not very big. At most, it is 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 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, and the foundation of EJB technology is RMI. Using RMI technology, J2EE
Create 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 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 a word throttling, you can use various byte stream classes in the Java. Io package to save the object to the 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 is to implement
For example, you customize a class myclass or any class object to convert it
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, you can handle it at will, of course, the most used is to send it to Remote Computing on the network.
On the machine. 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.
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 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 ".
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 advantages
This mechanism brings great convenience to distributed computing system design and programming. You only need to design the process according to RMI rules.
The network details under RMI, such as TCP and socket. Any two computers
RMI is responsible for communication between them. 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's it.
Yes, you can pass complex types like Java Hasse tables as a parameter.
4.5 disadvantages
If it is a relatively simple method call, the execution efficiency may be much slower than local execution, 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
Contains the returned 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. Although EJB uses RMI technology
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 EJB and when not to use EJB.
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 for Distributed operations, so that you can understand the so-called "service cluster" concept of EJB.
It is to put the classes previously computed on one computer into other computers for sharing operation
The CPU and memory resources required by these classes. At the same time, different software functional modules can also be placed in different
On the server, you can directly modify the classes on these servers when you need to modify some features.
The software of the user has been modified. 2 14.
6. Is this deployment impeccable?
As shown in figure 2 14, this "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 this configuration has a bottleneck, as shown in Figure 2 15.
Let's take a look at the structure shown in Figure 2 15. If you want to query the same database for each server
No matter how many functional servers you deploy, You need to query a database server. That is to say,
No matter how "computing" is distributed ", you also need to retrieve data from a server. Although, 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 each server.
Request.
Therefore, through this structure, we learned that EJB cannot completely solve the load problem, because, the bottleneck
It is not where the function module is located, but on 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, so that it will not 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 ".
It is not easy to solve.
6.3 The network is facing great pressure, making your applications slow.
Let's look forward to the two networks in the architecture shown in Figure 2 15. 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 ADSL Network only has a bandwidth of 512 KB-2 MB.
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-consuming.
Therefore, the running speed of this application architecture is quite slow. It's not an exaggeration.
It's as slow as pulling a car.
A system such as Lao Niu:
At present, a large company that is engaged in operator network management systems on the Chinese Internet, one of its early network management software is
An application system that adopts the C/S structure.
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 application's actual user connection network, thus causing a greater impact to the company
This 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 great. In fact
Otherwise. If we understand the "client program" as a server, this can also be applied, and,
If the server calls ejbs to each other, the WAN bandwidth limit does not exist.
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 with other service programs, but the custom network protocol called or returned can solve the problem.
You do not need to use EJB.
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.