Set JVM parameters to view heap size

Source: Internet
Author: User
Tags xms jconsole

1. Set JVM parameters in eclipse
Open eclipse- window- Preferences- java- The installed JRE (for Java programs running in the current development environment, that is, Java programs running in Eclipse) edits the currently used JRE, in the default VM parameters, enter :

-xmx1024m-xms1024m-xmn256m-xss16m

Or, when running a Java program, execute:

Java -xmx1024m-xms1024m-xmn256m-xss16m Test

Test is a class file.

2. Set JVM parameters on the Tomcat server

set catalina_opts=-xmx512m-xms512m-xmn64m-xss2m or

Set java_opts=-xmx512m-xms512m-xmn64m-xss2m

setting catalina_opts and java_opts is a good idea to set parameters when you start Tomcat.

The difference is that java_opts also executes this command when Tomcat is stopped.

Note: Tomcat is divided into the installation version (*.exe) and the non-installed version or the decompression version (*.zip), the individual or prefer the decompression version. There is no difference in functionality between the two, but there are areas to be aware of in the setup. This is where the JVM settings should be noted.

installation version:Windows services will have a Tomcat service that will read the JVM parameters from the registry when the service is started. This means that it is not valid to set JVM parameters in Catalina.bat or Startup.bat under the Lib folder of Tomcat. Workaround: Set up the Tomcat registry, or use Startup.bat to start Tomcat.

Decompression Version: When you click startup.bat , it reads the configuration in the Catalina.bat , whether in startup.bat file or The JVM parameters are read in the Catalina.bat file.


3. View the size of the heap

when viewed in a program, the return value units are bytes and of course other JVM parameters can be viewed.

runtime.getruntime (). MaxMemory ();


or execute the JVISUALVM command at the command line

or click jvisualvm.exe in the%java_home%\bin directory

or execute the jconsole command at the command line

or click jconsole.exe in the%java_home%\bin directory

4. Java memory can be divided into heap memory and non-heap memory

Heap and non-heap: The heap is for developers, and is created when the JVM is started; Non-heap is the information that is left to the JVM for its own use for storing types (classes and interfaces). Unlike heaps, the GC does not free up space during the run time. If the Web app uses a large number of third-party jars, or if the application has too many class files, and the MaxPermSize setting is small, exceeding this will cause the memory to overflow too much, or the Tomcat hot deployment will not clean up the previously loaded environment, Only the context will be changed to a newly deployed, non-stockpiled content will be more and more, hot deployment several times on java.lang.OutOfMemoryError:PermGen space.

----Heap Memory settings: Programs can be reached, can be manipulated
-xms initial heap memory default physical memory 1/64, which is also the minimum allocated heap memory. When the free heap memory is less than 40%, it increases to the maximum limit of-XMS

-xmx maximum heap memory allocation default physical memory 1/4, when free heap memory is greater than 70%, the minimum limit to-XMS is reduced.
General Settings-xms and XMS size are equal

----Non-heap memory settings
-xx:permsize The initial value of non-heap memory, which is 1/64 of the default physical memory and also the minimum non-heap memory.
-xx:maxpermsize Non-heap memory maximum, default physical memory of the


5. Typical JVM parameter settings:

Java-xmx128m-xms128m-xmn64m-xss1m

-xmx128m: Sets the maximum available memory for the JVM to 128M.

-xms128m: Set JVM minimum memory to 128m. This value can be set to the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes.

-XMN2G: Set the young generation size to 2G. The entire heap size = younger generation size + old generation size + persistent generation size. The permanent average fixed size is 64m, so increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is 3/8 for the entire heap.

-xss128k: Sets the stack size for each thread. After JDK5.0, each thread has a stack size of 1M, before each thread has a stack size of 256K. Adjusts according to the size of the memory required by the application's thread. In the same physical memory, reducing this value can generate more threads. However, the operating system of the number of threads within a process is still limited, can not be generated indefinitely, the empirical value of 3000~5000 around.

--Ratio English: [' reiseu] ratio
-Eden Eden
--Survivor survivors

Java-xmx3550m-xms3550m-xss128k-xx:newratio=4-xx:survivorratio=4-xx:maxpermsize=16m-xx:maxtenuringthreshold =0

-xx:newratio=4: Sets the ratio of the young generation (including Eden and the two survivor zone) to the old generation (except for the persistent generation). Set to 4, the ratio of the young generation to the old generation is 1:4, and the younger generation takes up 1/5 of the entire stack.

-xx:survivorratio=4: Sets the ratio of the size of Eden and survivor in the younger generation. Set to 4, the ratio of two survivor to one Eden area is 2:4, and a survivor area represents 1/6 of the entire young generation.

-xx:maxpermsize=16m: Set the persistent generation size to 16m.

-xx:maxtenuringthreshold=0: Sets the maximum age for garbage. If set to 0, then the young generation object does not go through the survivor area, directly into the old generation.
For older generations of more applications, can improve efficiency. If this value is set to a larger value, the younger generation objects are duplicated multiple times in the Survivor area, which increases the survival time of the object's younger generations, increasing the introduction of being recycled in the younger generation.

From

http://josh-persistence.iteye.com/blog/1981784

http://xiaomogui.iteye.com/blog/857815

Set JVM parameters to view heap size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.