Java high concurrency, how to solve, what way to solve (go)

Source: Internet
Author: User

Before I mistook the high concurrency solution is a thread or queue can be resolved, because high concurrency is a lot of users in the access, resulting in incorrect system data, loss of data phenomenon, so think of the queue to solve, in fact, the way the queue solution can also be handled, such as we are in the auction of goods, Forward comments microblogging or seconds to kill the goods, etc., the same time the traffic is particularly large, the queue to play a special role in the queue, all requests into the queues, in milliseconds units, orderly, fromWithout the data loss system data is incorrectCase

Today, I checked the data, there are two kinds of high-concurrency solutions , one is to use the cache, the other is to use to generate static pages, and to optimize our writing code from the most basic places to reduce unnecessary waste of resources:(

1. Do not frequent new objects, 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.

2. 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 to do not use instanceof to make conditional judgments, try to use the ratio of criteria to determine the way. Use the high efficiency classes in Java, For example, ArrayList is better than vector performance. )

First cache technology I have not used, I think it should be in the user's request to save the data in the cache, the next request will be detected in the cache for the presence of data, to prevent multiple requests to the server, resulting in degraded server performance, causing serious server crashes, which is my own understanding, Detailed information is still required to be collected online;

Using generate static pages I think we should not model, we have seen many sites when the page after the most changes in the request, such as "http://developer.51cto.com/art/201207/348766.htm" the page is actually a server request address, After converting to HTM, the access speed will be increased because the static page does not have a server component; Here I would like to introduce a lot:

First, what is the page static:

Simply put, if we access a link, the server corresponding module will process the request, go to the corresponding JSP interface, and finally generate the data we want to see. The drawback is obvious: Because each request server will be processed, if there are too many high concurrent requests, then it will aggravate the application server pressure, do not make the server down. So how to avoid it? If we save the results of the TEST.DO request to an HTML file and then every time the user accesses it, the pressure on the application server is not reduced.

So where does the static page come from? Can't you just let us handle each page manually? This involves the content we are going to explain, static page generation scheme ... What we need is automatic generation of static pages, when the user accesses, will automatically generate test.html, and then display to the user.

Second, the following is a brief introduction to the page to grasp the static solution should grasp the knowledge points:

1. Base-URL Rewrite

What is URL Rewrite? URL rewriting. Use a simple example to illustrate the problem: enter the URL, but actually the access is abc.com/test.action, then we can say that the URL is rewritten. This technology is widely used, and there are many open source tools to implement this feature.

2. Foundation-Servlet Web. xml

If you don't yet know how a request in Web. XML matches a servlet, search for the servlet's documentation. This is not nonsense, a lot of people think/xyz/*.do such a matching method can be effective.

If you don't yet know how to write a servlet, then search for a servlet. This is not a joke, in a variety of integration tools flying all over the sky today, many people will not go from zero to write a servlet.

Three, the Basic program introduction

In this case, for the part of the URL rewriter, you can use a fee or open source tools to implement, if the URL is not particularly complex, you can consider the implementation in the servlet, then this looks like this:

Summary: In fact, we rarely consider this problem in the development, the direct is to implement the function first, when a programmer in the dry to 1-2 years, will feel that the light realization function is not the most important, security performance, quality and so is a developer is the most concerned. Today I said is high concurrency, my solution is, 1, the use of distributed Application Design 2, distributed cache database 3, code optimization

Java high concurrency, how to solve, what way to solve (go)

Related Article

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.