In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the skills of quickly mastering Java performance tuning". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the skills to quickly master Java performance tuning"?
1. Don't optimize until you make it clear that it is necessary.
This is probably one of the most important performance optimization techniques. You should follow common best practices and apply them efficiently in your cases. But that doesn't mean you should replace any standard libraries or build complex optimizations before proving it is necessary.
In most cases, tuning prematurely takes a lot of time and makes the code difficult to understand and read. To make matters worse, these optimizations usually don't bring any benefits, because you spend a lot of time optimizing non-critical parts of the application.
So, how do you prove that things need to be optimized?
First, you need to define how fast your code is. For example, specify a maximum response time for all API calls, or specify the number of records to import within a specific time range. After doing this, you need to determine which parts of your application are too slow and need to be improved. When you're done with this, you can take a look at the second tip.
two。 Use the analyzer to find the real bottleneck
After completing the optimization recommendations in the first part to identify the parts of your application that need to be improved, where do you start?
You can solve this problem in two ways:
Look at your code and start with what looks suspicious or where you think it might cause a problem.
Or use the parser to get details of the behavior (execution process) and performance of each part of the code.
I hope I don't need to explain why I should always follow the second approach / approach.
Obviously, the parser-based approach allows you to better understand the performance impact of your code and allows you to focus on more critical parts (code). Even if you've ever used a parser, you must remember how surprised you were to find out which parts of the code had performance problems. My first guess caused me to go in the wrong direction more than once.
3. Create a performance test suite for the entire application
This is another general-purpose technique that can help you avoid many of the unexpected problems that often occur after performance improvements are deployed into the product. You should always define a performance test suite to test the entire application and run it before and after performance improvements.
These additional test runs will help you identify the functional and performance side effects of your changes and ensure that they do not lead to updates that do more harm than good. This is especially important if you are dealing with components that are used by many different parts of the application, such as databases or caches.
4. Give priority to the biggest bottleneck
After creating a test suite and using an analyzer to analyze your application, you can make a list of issues that need to be addressed to improve performance. That's good, but it doesn't answer the question of where you need to start. You can focus on quick solutions, or start with the most important questions.
A quick plan may be attractive at first because you can quickly show the first result. Sometimes, however, it may be necessary to convince other team members or management that performance analysis is worth it.
In general, I suggest starting at the top level and starting with the most important performance issues. This will provide you with the greatest performance improvement, and you may need to solve only a few of these problems to meet your performance requirements.
This is the end of common general tuning techniques. Next, let's take a closer look at some Java-specific techniques.
5. Connect strings programmatically using StringBuilder
There are many different options in Java to concatenate strings. For example, you can use simple + or + =, as well as the old StringBuffer or StringBuilder.
So, which method should you choose?
The answer depends on the code of the connection string. If you are adding new content to a string programmatically, such as in a for loop, you should use StringBuilder. It is easy to use and provides better performance than StringBuffer. Keep in mind, however, that StringBuilder is not thread-safe compared to StringBuffer and may not be applicable in all cases.
You just need to instantiate a new StringBuilder and call the append method to add a new part to the String. After you have added all the parts, you can call the toString () method to retrieve the concatenated string. The following code snippet shows a simple example.
During each iteration, the loop converts I to a String and adds it to the StringBuilder sb along with spaces. So, finally, this code writes "This is a test0 1 2 3 4 5 6 7 8 9" in the log file.
StringBuilder sb = new StringBuilder ("This is a test"); for (int item0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.