加速Java [英] Speeding Up Java

查看:94
本文介绍了加速Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是两个问题,但它们非常相似,为了保持简单,我想我只是把它们放在一起:

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:


  • 首先:鉴于已建立的Java项目,除了简单的代码内优化之外,还有哪些方法可以加快速度?

  • Firstly: Given an established Java project, what are some decent ways to speed it up beyond just plain in-code optimization?

其次:在Java中从头开始编写程序时,有哪些好方法可以大大提高性能?

Secondly: When writing a program from scratch in Java, what are some good ways to greatly improve performance?

请远离一般优化技术,除非它们特定于Java

Please stay away from general optimization techniques unless they are Java specific.

我问过这个关于 Python Perl 早些时候。对于Java,我想知道有什么好的提示/技巧来提高性能以及是否有任何特别好的Java分析器。

I asked this about Python and Perl earlier. For Java I'm wondering what good tips/tricks are out there to improve performance and if there are any particularly good Java profilers.

推荐答案

<首先:通过代码优化,我会假设您已经完成了正确的算法和正确的算法实现。在这种情况下,您将使用分析器并查看您的垃圾收集器(GC)收集垃圾的频率以及它用于执行此操作的时间。然后你开始研究GC选项 - 但要注意,如果你不知道你在做什么,你可能会遇到麻烦。

我假设你使用的是java 5/6。在这种情况下,我将通过 http:http: //java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html 。还有一个关于java性能的非常好的新信息,称为 http://www.javaperformancetuning.com/ 。你可以订阅。

Firstly : by code optimization, I would assume that you've done the right algorithms and right implementation of algorithms. In which case, you would use the profiler and look at how often your garbage collector(GC) is collecting garbage and how much time it is using for doing that. Then you start working on the GC options -- but beware you can get into trouble if you don't know what you're doing.
I assume that you're using java 5/6. In which case, I'd go through the java 5 tuning guide at http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html. There is also a very very good newletter on java performance called http://www.javaperformancetuning.com/ to which you can subscribe.

除此之外,看一下你可以消除多少个try / catch块。看看你是否可以消除不必要的异常抛出。

Other than that, look at how many try/catch blocks you can eliminate. See if you can eliminate unnecessary throwing of Exceptions.

使用Caches你可以但不要过度。

Use Caches where you can BUT don't over do it.

阅读有效的Java,第1版和/或第2版

Read Effective Java, 1st and/or 2nd Edition

Profilers:我使用yourkit。这对于java 1.5及更高版本来说非常好。您可以获得个人许可。其他分析器也很好。

Profilers : I use yourkit. It's pretty good for java 1.5 and above. You can get a personal license. Other profilers are also good as well.

就像你有单元和集成测试一样,在你的连续集成中运行一些性能测试也没什么坏处(CI)构建。通过这种方式,您可以了解何时退化,尤其是在使用良好的CI构建服务器时。

Just like you have unit and integration tests, it does NOt hurt to have some performance tests that you run as part of your CONTINUOUS INTEGRATION(CI) builds. This way you know when you regressed, especially if you are using a good CI build server.

这篇关于加速Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆