What is J2EE?

Source: Internet
Author: User

Currently, all B/S system applications can be classified into statefull and stateless. Stateful means that some information should be retained throughout the processing of the system, while stateless means that, on the contrary, each request is an independent connection and data sharing is not required between each request.

For these two applications, the first consideration is generally the optimal performance. performance is one of the main bases for us to choose it technology.

In order to maximize the performance, for Java systems, the previous common practice is to use the object pool, which saves the performance overhead during object generation, that is, when the system is started, A certain number of object instances are pre-generated in the memory. When you need to use them, the instances are taken out of the Object pool, used up, and returned to the object pool. For stateful applications, you can use persistence) policy to save the status.

In the next step, it will be very important to access the object pool in parallel. Java's multithreading technology provides implementation possibilities, and thread creation and destruction may be time-consuming, like using an object pool, we must use a thread pool to optimize multi-thread parallel computing.

Using the thread pool and Object pool, each time a client request occurs, a thread is borrowed from the thread pool. After processing the request, the thread is returned to the thread pool. Similarly, the thread can quickly access the object, the object is also borrowed from the object pool and is returned to the object pool after use. The overall architecture design is optimal in terms of performance.

With performance guarantee, security mechanisms, transaction mechanisms, and cluster technologies will also be the main basis for selecting IT technologies.

J2EE is a comprehensive standard framework system that implements the above considerations. In actual use, we may not pay the same attention to the requirements of all these considerations, for example: if the Pure Pursuit of performance is the first, you can ignore the transaction mechanism, then the complete J2EE technology may not be suitable for you.

So let's first look at how J2EE ensures that our application system runs at the fastest speed in terms of performance. That is to say, J2EE must have the Implementation Technology of the above thread pool and Object pool, servlet is actually a better thread container Based on the thread pool; EJB is a better object container Based on the object pool.

Let's take a look at the architecture of servler:

 

When Client1 requests, the servlet container will allocate a thread from the thread pool to this request.


Let's look at the architecture of EJB:



As an object instance pool, the instance pool maintains the EJB instance. Of course, this object pool uses a lifecycle. In short, EJB = Object pool + Remote Object pool.

However, EJB also integrates other enhanced functions, such as the security transaction mechanism, which are required for general applications. Of course, you must also choose whether to use J2EE based on your needs, if your application has no requirements for the secure transaction mechanism, you can use the thread pool and Object pool technology to obtain the best performance.

Therefore, based on the principles of servler and EJB, we can plan our application, what can be put in servlet, or what needs to be implemented in EJB:

The nature of the thread determines that servlet is only suitable for some lightweight applications, such as analyzing simple XML documents, accessing data sources through JDBC, and using JMS or javamail to process simple information messages, or use JTs/JTA to process simple transactions. Note that these terms are "simple". If complicated, you need to use EJB.

The following describes the use of these two technologies from the client and server. The client here does not necessarily refer to the final client, because J2EE is a multi-layer structure, the middle layer may be implemented on multiple servers. If the services on one server are accessible to applications on another server, the latter is also called a client.

Depending on the complexity and requirements of the application, the following situations are involved:

1. Some applications that can be implemented at the web layer

If your system does not have complex transaction processing or accesses many of the original resources of the Enterprise, you can use some help classes such as Javabean to implement your application. However, this solution is not the cleanest, most effective, or the most scalable.

Otherwise, all core computations are placed in the EJB.

2. All complex business computing cores are completed in EJB

If there is a firewall between your client and the server, the protocol that can pass through the firewall is only HTTP (WebService is also based on HTTP). Now that HTTP is used, servlet is based on the HTTP protocol, so it is necessary to access EJB through servlet, which is our most common application.

However, if your client and server can be placed in a network without a firewall, you do not need to use servlet to directly use Java to call RMI to access ejbs, this is the best performance. At this time, the servlet is probably only used to control the output of the JSP page (the control function in the MVC mode ).

If the client is not a Java client, you can access EJB through the CORBA component.

3. If your application requires a high speed and high requirements, there will be almost no requirements for transaction processing and other aspects.

Using j2se directly, along with the thread pool and Object pool technology, will bring your java system performance to the extreme. Jakarta.apache.org has the source code of these two technologies. The thread pool can be found from the source code of the servlet container tomcat.

What is J2EE?

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.