Solve application Java application performance dry


You Rui core courses through java study notes, we can see that a lot of the code of professional knowledge, learning to share your reference.

If you are a Java developer, you may need to hear some tips to keep the performance of the application.

In resolving upon the problem (especially application performance) related NFR, I always wondered why we, as developers less emphasis on performance (there are always exceptions to honor). This is due to a lack of understanding of it?

In many cases, we are only at the time of performance testing before deployment or to start thinking about performance.

Speed (speed) and increased volume (size) has affected our daily lives: Our phone from 2G into a 4G, and 40-80 GB of hard drive used to be a luxury, and USB hard drives now reached TB.

The importance of application performance

For any application that we must deliver with these characteristics.

1. function properly;

2. Performers

3. Appearance: it should have a reasonable structure, readable, reusable code, and use the latest frameworks, libraries, and tools;

 

4. Test Range: Function should pass the test tool to verify the application covers all the intended function.

I have seen that many of us have in delivering applications in line with performance. So why do I want performance on the second place it? Let's take an example : As an employee,

·  I every morning 8 o'clock to the office in 30 minutes for lunch and 15 work-minute tea break time, 9 hours, and then in the afternoon 5 out of office (correct function) around the point;

·  · I strictly adhere to all office manners, always shaved, dressed for work clothes, my desk is always clean (appearance)

·  · My daily travel card, system login and supervision (test coverage) write-off and the manager can verify my office attendance.

Now, if I take ten days to complete the two-day work, how to do? That means I'm not good. If I performed poorly, my organization will allow me to work for them? 

Observation results

For developers with full respect for the right code delivery functions for all the efforts, I share some views.

Thread improper use

For each iteration, generates a thread, the program will wait until the end of the thread, so that the entire sequence of behavior .

Instead, it should be filled within the loop Runnable / Callable list, and then use parallel processing to call all threads immediately.

Calling a cycle database to obtain the primary data, the circulating collection Static Static value creation

It's like a time of international travel have applied for a new passport the same. When the application starts, load the cache only and all master data, constants and configuration fields once and use them throughout the application.

Date format such as object creation in the loop

Each time formats cycle "ddMMyyyy" like to create a new object What are the benefits? Define a constant, and used anywhere. Java 8 has a DateTimeFormatter class that has some predefined constants.

Loop recording purposes only and aim to create a timestamp objects

在循环中创建一个新的TimeStamp对象,仅用于记录当前日期时间。 不是所有当前的日志框架都支持模式来记录类,方法,日期时间等吗? 请使用日志框架的那些功能。

诸如响应之类的网络连接对象未关闭

随着网络请求数量的增加,网络将成为瓶颈,并且由于打开的网络连接数量而导致网络性能下降。每当网络任务完成时,请关闭连接。

正如我们在现实生活中所说的,每一分钱都很重要。不要使用诸如String.valueof(int)之类的方法,该方法反过来调用Integer.toString(int),您将通过使用Integer.toString(int)保存一个方法调用。

结论

的确,要使应用程序正常运行,必须考虑当前和将来的NFR,仔细设计其架构(高低)。

但是,作为开发人员,我们在某些领域可以肯定地应用优化,这将有益于整体应用程序性能。我们正在朝着基于云的体系结构迈进,在这种体系结构中,每次使用资源都会产生成本,因此请记住,没有什么是免费的。


提供功能时,请问自己,我可以进一步优化此代码吗?


> 喜欢这篇文章的可以点个赞,欢迎大家留言评论,记得关注我,每天持续更新技术干货、职场趣事、海量面试资料等等

 > 如果你对java技术很感兴趣也可以交流学习,共同学习进步。 

> 不要再用"没有时间“来掩饰自己思想上的懒惰!趁年轻,使劲拼,给未来的自己一个交代


文章写道这里,欢迎完善交流。最后奉上近期整理出来的一套完整的java架构思维导图,分享给大家对照知识点参考学习。有更多JVM、Mysql、Tomcat、Spring Boot、Spring Cloud、Zookeeper、Kafka、RabbitMQ、RockerMQ、Redis、ELK、Git等Java干货



 微信图片_20200227100004.png微信图片_20200225115155.png


Guess you like

Origin blog.51cto.com/14634606/2485571