Java Best Practices

Source: Internet
Author: User

A: Do not directly new thread, you should use the thread pool. Thread pool should be used when the number of threads reasonable set, the general maximum not more than 50, of course, you need to consider your IO and CPU, how to analyze the Internet search it.

Second: Container class variables, if the change is relatively large and frequent , as far as possible to define the initial capacity to set the size, reduce the consumption of expansion.

Third: When the branch Judge If...else, the most commonly-met conditional processing is placed in front.

Four: Object comparison when the constant put in front, develop good habits, reduce the appearance of null pointers.

Five: Reduce the synchronized waiting for processing code, can be placed outside as far as possible on the outside.

Six: two large table of association query, you can use two access to the database instead, first to find out the data of a table, using the related fields and then check B table. Don't blindly think of a SQL to do the best.??

Seven: resolutely avoid, check the whole table data or large amount of data, returned to the list loaded into memory, accidentally checked 100w data, and check more frequently, the memory burst. There is this risk of changing the composition page query.

Eight: Consider avoiding long connections or long transactions inside a transaction, which can affect performance if a large number of this situation takes up a data connection. Some unnecessary logic can be placed outside of the transaction execution.

IX: A normal index

b Uniqueness index with unique parameter, primary key.

C Single-column index

d Multi-column indexes are used only when the first field in these fields is used in a query condition

e Full-text indexing A full-text index can only be created on a field of char, varchar, or text type. Full-text indexing can improve query speed when querying a field of a string type with a large amount of data.

Ten: Generally a table index not more than 5, and avoid repeating the index, but also not indexed, according to the Index field criteria query, the index will work.

11: The condition of the index failure:

Use the LIKE keyword to match the first scene of the string to "%".  

Data rows on the Access table exceed the total table record number 30%, becoming a full table scan

Query criteria use a function on an indexed column, or on an indexed column

In a multicolumn index, the first index column uses a range query and can use only partial or unusable indexes

In a multicolumn index, the first query condition is not the leftmost index column

   

Java Best Practices

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.