确定 Java 程序的哪些部分需要优化
我想优化我的 Java 源代码,但我不确定代码的哪些部分可以优化。是否有任何工具或技术可以用来优化我的 Java 源代码?
我知道代码优化的基本原理,但我有大量的行和非常复杂的源代码(Java 类)。
我可以在 Java 分析器的帮助下优化我的代码吗?
提前致谢!
I want to optimize my Java source code, but I am not sure what parts of my code may be optimized. Is there any tool or any technique through which I can optimize my Java source code?
I know the basic fundamentals of code optimization, but I have a large number of lines and very complex source code (Java classes).
Can I optimize my code with the help of a Java profiler?
Thanks in Advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
优化代码是什么意思?您想重构您的代码以简化它吗?在这种情况下,我建议您使用 IDE 来帮助重构代码。
如果您想最大限度地减少其内存/CPU 消耗,我建议您使用 VisualVM 或 YourKit 等分析器来确定资源消耗的位置。
代码分析工具还可以帮助发现明显的性能问题。当我在 IDE 中输入内容时,我会进行代码分析,这有助于我在编写代码时发现这些问题。
What do you mean by optimising your code? DO you want to refactor your code to simplify it. In that case I suggest you use your IDE to help refactor the code.
If you want to minimise its memory / CPU consumption, I would suggest you use a profiler like VisualVM or YourKit to idenify where resources are being consumed.
A code analysis tool can also help pick up the obvious performance issues. I have code analysis on as I type in my IDE which helps me pick up those issues as I write it.
性能优化 - 是的,分析器可能会有所帮助。至少它可以向您显示应用程序中那些占用了意外 CPU 时间的区域。
但在开始应用更改之前 - 请注意不要进行一些微优化。首先看看改进算法。有时我们使用嵌套的 for 循环,而一项任务可以用单个循环完成(线性时间)。仔细检查您是否使用了正确的集合类型。然后看看您是否意外创建了超出需要的对象(循环中的对象创建是性能问题的典型原因)。
Performance optimization - yes, a profiler may help. At least it can show you those areas in your application that take an unexpected amount of CPU time.
But before starting to apply changes - take care not to do some microoptimization. Look at improving algorithms first. Sometimes we use nested for loops while a task can be done with a single one (linear time). Double check if you use the correct collection types. Then have a look if you accidentally create more objetcs than needed (object creation in loops is a typical reason for performance problems).
它们是用于静态代码分析的几种工具(用于对代码进行代码风格/代码约定/最佳实践/错误“优化”)。
我建议使用 声纳。它涵盖了所有内容并且易于设置 - 即使在本地计算机上(解压缩并启动)。它最适合与 Maven 项目一起使用,但也可以用于 非 maven 项目。
Their are several tools for static code analyzes (to do code style / code convention / best practises / bug "optimization" of your code).
I would recommend using Sonar. It covers them all and is easy to setup - even on a local machine (unzip and start). It is best used with maven projects but also possible for NON maven projects.