Домой United States USA — software 5 Java Performance Optimization Tricks 5 Java Performance Optimization Tricks

5 Java Performance Optimization Tricks 5 Java Performance Optimization Tricks

152
0
ПОДЕЛИТЬСЯ

Optimizing your Java code requires a proper analysis of how it works. There are several factors that affect performance optimization.
Optimizing your Java code requires a proper analysis of how it works. There are several factors that affect performance optimization, like garbage collection, OS settings, and virtual machinery.
I recommend that you start with minimum memory allocation. Then, you can gradually increase it depending upon the program requirements. You can instruct the JVM to dump the heap on an OutOfMemoryError exception by adding the following argument to the JVM:
Proper utilization of the available memory is a great way to optimize for speed.
A heap size of 1GB to 7GB is sufficient to get started. It should depend on an old generation to new generation-object ratio.
There are several Java performance tools like VisualVM, YourKit, Java Mission Control, etc., which you can use to keep a track of your application performance.
The NetBeans profiler is also a great option. NetBeans IDE supports the development of all Java application types Java SE (including JavaFX) , Java ME, web, EJB, and mobile applications — out of the box.
The below code could come handy in place of two separate codes of StringBuilder:
This makes any amendment easy without putting extra pressure on the GC.
If we use a code like:
Then every time we run this code, a new iterator instance will be created that will consume much of our memory.
Instead, the following code is recommended:
…or, if your list doesn’ t really change, you might even operate on an array version of it:
Writing index-based iterations is extremely useful.
Concurrency is the ability to run multiple programs in parallel to each other.
For tackling multi-request web flows, it is recommended to use optimistic locking with detached entities or an EXTENDEDPersistence Context .
Moreover, it is essential to understand the inner workings of the relational database management system (RDBMS) and the data access frameworks in order to improve the performance of the data access layer.

Continue reading...