This is a brief guide of of import JVM options which yous volition oft run into amongst production Java systems. As a Java developer, yous should know what these JVM options agency too their importance. You volition honor that most of the JVM options are related to heap retention settings, garbage collection too to log around details e.g. heap dump, necessary for troubleshooting whatever number e.g. memory leak or excessive retention consumption. It's ok if yous don't know them all the same but yous should know them too that's the objective of this article. How exercise yous honor the JVM options your application is using? Well, yous tin run into the startup scripts through which your application is started. Alternatively, if your application is running on Linux yous tin exercise ps -ef | grep java to honor the Java physical care for too run into the JVM options printed equally physical care for arguments. If to a greater extent than than 1 Java physical care for is running on the organisation too thence yous may postulate to search amongst a keyword which is unique to your Java application.
Remember, your physical care for powerfulness non grab amongst ps -ef, if the declaration listing is also long, thence yous tin also endeavor using ps -auxww command, which shows the physical care for amongst a long declaration listing equally well. Once yous bring that listing of JVM flags, yous tin empathise surely behaviors of whatever Java application e.g. Tomcat, peculiarly how much retention is left to grow etc.
Btw, this is non the guide for JVM surgical physical care for tuning, it volition only allow yous familiar amongst essential JVM options from Java developer's perspective. You should refer Java Performance The Definitive Guide By Scott Oaks for a comprehensive learning on JVM internals too Java surgical physical care for tuning.
1) -Xms
This choice is to specify starting heap size for JVM e.g. -Xms2048m agency initial heap size of JVM is 2GB. When JVM volition starting fourth dimension the heap retention volition hold upwards this big. This is done to preclude resizing during startup too ameliorate the startup fourth dimension of JVM.
2) -Xmx
This choice is to specify maximum heap size of JVM e.g. -Xmx2048m agency maximum heap size of JVM volition hold upwards 2GB. You volition almost ever run into -Xms too -Xmx together. Their ration is also important, the ration of 1:1 or 1:1.5 is works life to hold upwards to a greater extent than efficient. You must specify sufficient heap infinite for your Java application to avoid java.lang.OutOfMemoryError: Java Heap space, which comes if in that location is non plenty retention to exercise novel objects or arrays.
3) -XX:PermSize
Earlier JVM options specify the size of heap retention but this 1 is to specify the size of PermGen space, where string puddle too class metadata is stored. This choice is really of import for the spider web server similar Tomcat which oft loads classes of the spider web application during deployment. It's worth knowing that PermGen infinite is replaced past times MetaSpace inwards Java 8 too this choice is non relevant if yous are running amongst JRE 8 JVM. See Java Performance Companion by Charlie Hunt to acquire to a greater extent than near Java 8 changes too their surgical physical care for impact. It is the most up-to-date mass inwards Java surgical physical care for till engagement too assist yous to crush the best surgical physical care for amongst JDK 8 inwards whatever application.
4) -XX:MaxPermSize
This is the counterpart of before JVM choice too used to specify the maximum size of permanent generation of JVM. The permgen volition expand until it reaches this value, It cannot expand beyond this. If the permanent generation of JVM is total too thence yous volition acquire java.lang.OutOfMemoryError: PermGen space. So, this choice is really of import to avoid that error.
5) -verbose:gc
This JVM choice is used to enable Garbage collection logging inwards your Java application. It volition demo yous whether it's major or fry garbage collection, which form of garbage collector is used, how much retention is reclaimed too how much fourth dimension it took etc.
6) -XX:+PrintGCTimeStamps
This JVM choice volition prepend tape amongst timestamp since Java application start, thence yous tin run into that at which patch of your application GC activeness peaks.
7) -XX:+PrintGCDetails
Prints around to a greater extent than garabage collections details
8) -Xloggc:[path to gc log file]
You tin log all garbage collection details into a log file for futurity analysis using this JVM option. You tin later on purpose tools similar GCViewer to analyze the logs files.

9) -Dsun.net.inetaddr.ttl=
This is an essential JVM choice if your Java computer programme connects to database or whatever other Java processor spider web server via a load balancer e.g. inwards which hostname tin hold upwards routed to the dissimilar IP address inwards instance of failover. This choice specifies the number of seconds during which DNS tape volition hold upwards cached inwards JVM. This is fifty-fifty to a greater extent than of import amongst Java vi virtual machine which caches the IP address forever. In that case, yous don't bring other choice but to restart your Java application if upstream or database switched to the secondary node, non the most elegant option.
10) -XX:+HeapDumpOnOutOfMemoryError
This JVM choice creates a heap dump when your JVM dies amongst OutOfMemory Error. There is no overhead involved unless an OOM genuinely occurs. This flag is a must for production systems equally it is oft the solely way to farther analyze the problem. The heap dump volition hold upwards generated inwards the "current directory" of the JVM past times default. If yous desire to exercise heap dumps on specific directory too thence purpose -XX:HeapDumpPath=[path-to-heap-dump-directory] e.g. -XX:HeapDumpPath=/dsk3/dumps.
Remember that the heap dump file tin hold upwards huge, upwards to Gigabytes, thence ensure that the target file organisation has plenty space. You tin also refer Java Performance Companion 1st edition past times Charlie Hunt to acquire to a greater extent than near analyzing heap dump too thread dump inwards Java.
That's all inwards the to the lowest degree of essential JVM options must for a Java production system. As I said, every Java developer should familiar amongst these options too should non lay the Java application into production without having these JVM options. You may postulate to lay to a greater extent than JVM choice e.g. to choose a garbage collector e.g. ConcurrentMarkSweep or G1 too other network related parameters but this is a bare minimum ready of JVM choice for whatever production Java system.
Related Java too JVM tutorials for Java programmers
References
The Structure of Java Virtual Machine
The Complete listing of Java HotSpot VM Options
The guide of configuring default JVM too Java Arguments
Remember, your physical care for powerfulness non grab amongst ps -ef, if the declaration listing is also long, thence yous tin also endeavor using ps -auxww command, which shows the physical care for amongst a long declaration listing equally well. Once yous bring that listing of JVM flags, yous tin empathise surely behaviors of whatever Java application e.g. Tomcat, peculiarly how much retention is left to grow etc.
Btw, this is non the guide for JVM surgical physical care for tuning, it volition only allow yous familiar amongst essential JVM options from Java developer's perspective. You should refer Java Performance The Definitive Guide By Scott Oaks for a comprehensive learning on JVM internals too Java surgical physical care for tuning.
Must Know JVM options for Java Developers
Here is my listing of essential JVM options which are must for whatever productions organisation too I strongly believe that every Java developer should hold upwards familiar amongst these Java virtual machine flags. The listing is non large too it only include the most pop options. It doesn't include JVM options related to 32-bit or 64-bit or something similar -XX:UseCompressedOOP, which is quite of import for 64-bit Java virtual machine. For a to a greater extent than comprehensive listing of JVM options, yous tin run into this list.1) -Xms
This choice is to specify starting heap size for JVM e.g. -Xms2048m agency initial heap size of JVM is 2GB. When JVM volition starting fourth dimension the heap retention volition hold upwards this big. This is done to preclude resizing during startup too ameliorate the startup fourth dimension of JVM.
2) -Xmx
This choice is to specify maximum heap size of JVM e.g. -Xmx2048m agency maximum heap size of JVM volition hold upwards 2GB. You volition almost ever run into -Xms too -Xmx together. Their ration is also important, the ration of 1:1 or 1:1.5 is works life to hold upwards to a greater extent than efficient. You must specify sufficient heap infinite for your Java application to avoid java.lang.OutOfMemoryError: Java Heap space, which comes if in that location is non plenty retention to exercise novel objects or arrays.
3) -XX:PermSize
Earlier JVM options specify the size of heap retention but this 1 is to specify the size of PermGen space, where string puddle too class metadata is stored. This choice is really of import for the spider web server similar Tomcat which oft loads classes of the spider web application during deployment. It's worth knowing that PermGen infinite is replaced past times MetaSpace inwards Java 8 too this choice is non relevant if yous are running amongst JRE 8 JVM. See Java Performance Companion by Charlie Hunt to acquire to a greater extent than near Java 8 changes too their surgical physical care for impact. It is the most up-to-date mass inwards Java surgical physical care for till engagement too assist yous to crush the best surgical physical care for amongst JDK 8 inwards whatever application.
4) -XX:MaxPermSize
This is the counterpart of before JVM choice too used to specify the maximum size of permanent generation of JVM. The permgen volition expand until it reaches this value, It cannot expand beyond this. If the permanent generation of JVM is total too thence yous volition acquire java.lang.OutOfMemoryError: PermGen space. So, this choice is really of import to avoid that error.
5) -verbose:gc
This JVM choice is used to enable Garbage collection logging inwards your Java application. It volition demo yous whether it's major or fry garbage collection, which form of garbage collector is used, how much retention is reclaimed too how much fourth dimension it took etc.
6) -XX:+PrintGCTimeStamps
This JVM choice volition prepend tape amongst timestamp since Java application start, thence yous tin run into that at which patch of your application GC activeness peaks.
7) -XX:+PrintGCDetails
Prints around to a greater extent than garabage collections details
8) -Xloggc:[path to gc log file]
You tin log all garbage collection details into a log file for futurity analysis using this JVM option. You tin later on purpose tools similar GCViewer to analyze the logs files.

9) -Dsun.net.inetaddr.ttl=
This is an essential JVM choice if your Java computer programme connects to database or whatever other Java processor spider web server via a load balancer e.g. inwards which hostname tin hold upwards routed to the dissimilar IP address inwards instance of failover. This choice specifies the number of seconds during which DNS tape volition hold upwards cached inwards JVM. This is fifty-fifty to a greater extent than of import amongst Java vi virtual machine which caches the IP address forever. In that case, yous don't bring other choice but to restart your Java application if upstream or database switched to the secondary node, non the most elegant option.
10) -XX:+HeapDumpOnOutOfMemoryError
This JVM choice creates a heap dump when your JVM dies amongst OutOfMemory Error. There is no overhead involved unless an OOM genuinely occurs. This flag is a must for production systems equally it is oft the solely way to farther analyze the problem. The heap dump volition hold upwards generated inwards the "current directory" of the JVM past times default. If yous desire to exercise heap dumps on specific directory too thence purpose -XX:HeapDumpPath=[path-to-heap-dump-directory] e.g. -XX:HeapDumpPath=/dsk3/dumps.
Remember that the heap dump file tin hold upwards huge, upwards to Gigabytes, thence ensure that the target file organisation has plenty space. You tin also refer Java Performance Companion 1st edition past times Charlie Hunt to acquire to a greater extent than near analyzing heap dump too thread dump inwards Java.
That's all inwards the to the lowest degree of essential JVM options must for a Java production system. As I said, every Java developer should familiar amongst these options too should non lay the Java application into production without having these JVM options. You may postulate to lay to a greater extent than JVM choice e.g. to choose a garbage collector e.g. ConcurrentMarkSweep or G1 too other network related parameters but this is a bare minimum ready of JVM choice for whatever production Java system.
Related Java too JVM tutorials for Java programmers
- What is the difference betwixt JRE, JDK, too JVM inwards Java? (answer)
- How exercise yous honor if JVM is 32-bit or 64-bit? (answer)
- What is maximum heap size of 32-bit too 64-bit JVM inwards Windows too Linux? (article)
- What is the deviation betwixt Oracle HotSpot JVM too IBM JVM? (answer)
- When is a class loaded too initialized inwards JVM? (answer)
- What is the deviation betwixt Stack too Heap Memory inwards JVM? (answer)
- 5 Books to Learn Java Performance Tuning (list)
References
The Structure of Java Virtual Machine
The Complete listing of Java HotSpot VM Options
The guide of configuring default JVM too Java Arguments

0 Response to "10 Essential JVM Options for a Java Production System"
Posting Komentar