Java performance and memory optimization (Java memory optimization)

Source: Internet
Author: User

 

Java performance and memory optimization is one of the challenging tasks in Java programming. In case of big Java projects we must consider this. Here I listed few techniques for Java performance and memory optimization.

1. Use mutableStringbuffer/stringbuilderClasses instead of immutable string objects.

2. In caseI/O operationsUse buffering when writing to and reading from
Files and/or streams.Avoid Reader/writers use streamsInstead of this.

3.Remove references to the short-lived objectsFrom long-lived objects like Java collections.

3. Create objects before entering the loop andAvoid creating new objects for each iteration.

4. UseArraylists, hashmapInstead of vector, hashtable etc wherever possible.

5. Reduce calltoDate, calendar, Etc related classes.

6. Use logging frameworks likeLog4jWhich uses I/O buffers instead of system. Out. println.

7.Set Initial Capacity of a collection. Empty vector has array size 10.

8. Use tools likeJprofiler,Jprobe, optimizeitTo find memory leaks in your Java application.

9. Improve Java application performance usingSwingworkerClass.

10. UseThread pooling and database connectionPooling techniques wherever possible.

 

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.