How to handle high concurrency in Java

Source: Internet
Author: User

I. Overview of the background

Concurrency is the ability to use multiple threads or processes while processing (or concurrency) different operations.

High concurrency is a lot of users in the access, resulting in incorrect system data, embarrassing data phenomenon. For some large web sites, such as portals, in the face of a large number of user access, high concurrent requests, the basic solution is focused on a number of aspects: the use of high-performance servers, high-performance databases, high-efficiency programming language, as well as high-performance web containers. These solutions to some extent imply a greater investment.

Using a generic synchronized or lock or queue is not enough to meet the problem of high concurrency.

Second, there are three ways to solve the problem:

1. Using the cache

2. Using the Generate static page

HTML pure static pages are the most efficient and least expensive pages. We can use the information publishing system to achieve simple information entry automatically generated static pages, channel management, rights management and automatic capture and other functions, for a large web site, has a set of efficient, manageable information distribution system CMS is essential.

3. Image Server Separation

Images are the most resource-intensive, and zombie images and page separations can reduce the pressure on the server system that provides page access requests and ensure that the system does not crash due to picture problems.

3. Reduce unnecessary waste of resources when writing code:

    • Do not use the new object frequently, and use singleton mode for classes that only need to have one instance in the entire application. For string connection operations, use StringBuffer or StringBuilder. Classes for utility types are accessed through static methods.
    • Avoid using the wrong way, such as exception can control the introduction of methods, but exception to retain stacktrace consumption performance, unless it is necessary not to use the instanceof to make conditional judgments, try to use the ratio of criteria to determine the way. Using classes that are efficient in Java, For example, ArrayList is better than vector performance. )
    • Using Thread-Safe collection objects Vector hashtable
    • Using the thread pool

How to handle high concurrency in Java

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.