Make your Java Server faster

Source: Internet
Author: User
1. Nio

The new IO provided in JDK is used to process multiple connections and replace the IO model of the old client and thread.

The key to improving server performance is that NiO provides a non-blocking Io model for Java. In the past, a thread was needed to wait for user data. Now, you only need to use select to "select" The ready (ready) socket and then read the data. In this way, a few threads can be used to provide services to a large number of connected users at the same time, eliminating the overhead of thread switching.

2. Thread Pool (SEDA)

Break down the processing process of your server into stages, and assign each stage a thread pool to concurrently process events. Stages are converted through events.

The secret of Seda is that concurrency is advantageous in general. By dividing the processing process of the server into stages, the server's adequacy is improved. At the same time, each stage is configured with its own thread pool to handle its events. It can be refined to adjust the size of its pool and determine the concurrency of this stage. Although the founder of Seda wrote n complex sandstorm, the idea of Seda itself is very simple. Using jdk1.5 to provide us with good thread support, it is a hundred lines. Code To implement a Seda model.

3. Stax

Use Stax instead of Dom or sax. Streaming XML parsing consumes less memory and is faster.

Dom is very memory-consuming and cannot be considered in terms of performance. Sax is very huge and cool. It is slower than pull-type stream parser. Stax is the product of pull-type streaming parser standardization, and has been final JSR in 04 years. There is now an RI provided by BEA that uses the APL protocol. The server is generally implemented in a collaborative manner. It is usually stream-centric, rather than document-centric, and it often needs to control Parser for parsing. It is best to use Stax.

4. javolution

When a large amount of temporary memory is generated and used repeatedly, the javolution real-time framework is used to "precisely" manage the memory.

5. In general

Good memory management and proper concurrency make Program The key to better performance and stronger load capacity.

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.