Read about how to monitor java memory usage, The latest news, videos, and discussion topics about how to monitor java memory usage from alibabacloud.com
Recently, a project was designed to obtain information about the cpu usage and so on. At first, I thought it was necessary to use a dynamic link library, but later I found that I could do the following without calling jni, this saves a lot of time for reading new technologies...
In Java, you can obtain information such as the total physical memory, the remaining
multiples of 8, and the object occupies a multiple of the total space (object header + declaration variable) less than 8, and is automatically padded. And, these filled spaces, we can call it "filler." Let's take a look at the specific examples:
An empty object (without declaring any variables) takes up 8 bytes--> object Header occupies 8 bytes
A class that only declares a Boolean variable, occupies a bytes-to-Object header (8 bytes) + Boolean (1 bytes) + filler (7 bytes)
Class
Copy from:http://www.javamex.com/tutorials/memory/instrumentation.shtmlInstrumentation:querying the memory usage of a Java objectThe most reliable-but isn't necessarily the easiest-way to estimate the usage of a Java object are to
One of the best known advantages of Java technology is that, unlike other languages such as C programmers, Java programmers do not have to be responsible for daunting memory allocations and releases. The Java runtime can manage these tasks for you. Each instantiated object automatically allocates
, exclude 2. Use the Finalize function as little as possible. It will increase the workload of the GC.3. If you need to use a frequently used picture, you can use the Soft app type. It keeps the picture in memory as much as possible.4. Note the collection data types, including arrays, trees, graphs, linked lists, and other data structures, which are more complex for GC to recycle.5. Try to avoid creating and initializing a large number of objects in t
Java command simple view JVM memory usage1. JPS Virtual machine process Status ToolSyntax jsp [option] [HostID]OptionsRole-QShow Only Lvmid-MPass in Main method parameter when output virtual machine is enabled-LOutput main class full Name-VOutput JVM ParametersAttention:If the JPS command cannot output vmid data (jdk1.6.0.23/24 bug) in a Linux environment, the catalina.sh file needs to be modifiedIf [-Z "$C
Database Data occupies memory in Java. Conclusion: 1. database records are stored in JAVA. It takes about 4 times of memory space to use an object (which is a common ORM processing method), and 10 times of space to use HashMap to store KV data. 2. if your main data is text, you can estimate the space by two times. The
I have made some optimizations on the memory usage of the program recently, and have achieved good results. I have summarized some experiences.
I believe it will be helpful for you to write high-quality programs.
The following discussion is not applicable to 64-bit systems for 32-bit systems.
You often write a program, test it, and have no function problems. When you check that the
Mention of the memory usage when the Java process is running is a confusing place for many beginners, which is how the JVM applies the memory to the operating system when we run the compiled. class file.
You can use the JDK's own run-time system parameters to describe the three methods in class runtime to view
Runtime.
(411.06592559814453 MB)20.152302906758376% usedPS Perm GenerationCapacity = 85983232 (82.0 MB)Used = 60770232 (57.95500946044922 MB)Free = 25213000 (24.04499053955078 MB)70.67684080542588% used and then use ps to look at it:[Lex @ chou ~] $ Ps-p 837-o vsz, rssVSZ RSS7794992 3047320 I will not elaborate on the several generation online materials here. Here, we can calculate the sum and we can see that the former has allocated a total of 64 4 MB of memory
, which is definitely longer than getting an element from an array.Memory consumption
There is a good tool that can help us check the memory consumption of Java objects. Download the jar package from here: http://sizeof.sourceforge.net/Decompress the package and select sizeof. jar is copied to a directory, such as my/home/chenshu. Add this jar package to the project and set the JVM parameter-javaagent:/home
Test.jar Com.test.Test1However, these two methods are not recommended for use2, use the tool that comes with the JDK:2.1 JconsoleLaunch Jconsole.exe and Invoke Operation Dumpheap () on Com.sun.management.HotSpotDiagnostic MBeanDefinition of method: Dumpheap (String OutputFile, Boolean live)2.2 JPS and JmapRun JPS first to get the Java process IDC:\temp\test>jps8208 Test142367440 JpsJmap-dump:file=test2.hprof 8208You can refer to the following links f
In Java programming, you want to know the CPU usage to determine whether to load the task. First, search by google. In Windows, you can use JNI to Use API functions.GetProcessCPUTime (), and someone gives the source code. Linux does not seem to have any source code, so I decided to write it myself. After practice, I finally succeeded. Now I willPost the code and share it with you.
The idea is as follows: in
One, memory useSecond, Java Runtime data regions1. Program Counter:The line number prompt for the byte code executed by the current thread.2. Java Virtual machine stack:Thread private, the same as the thread life cycle, save the base data type, if the thread requested a stack depth greater than the virtual machine allowed depth, will throw stackoverflowerror, if
of memory occupied by a Java object?
Generally, the premise of heap memory usage we are talking about is "General situation. It does not include the following two situations:
In some cases, the JVM does not put the object into the heap at all. For example, in principle, a small thread-local object exists in the sta
The performance of TWaver Java is obvious to all. What about memory usage? What is the memory growth under different orders of magnitude? What is the impact of view components on memory? We respectively tested to add only the Network Element DataBox to add the Network Elemen
when using netstat query port, always can not see the name of the program, you must also cooperate with PS to the process number intersection, a two can, often need to see the words are silly, this script is to solve such a pain point, especially to optimize the Java program memory. on a night of Black nights, I had a long-running awk code, and finally did it, and after several optimizations, the execution
You want to know the CPU usage during Java programming so that you can decide whether to load the task. First with Google search, Windows environment can use JNI through the API function Getprocesscputime () to get, and someone gave the source code. Linux seems to have no one to give the source code, so decided to write one, after practice, and finally succeeded, is to post code, and share with you.Thinking
Check tomcat memory usage by the program and view tomcat memory usageRecently, the company's online tomcat often has no chance of downtime, and summarizes the problem locating methods for reference only:Error message:
Maximum number of threads (200) created for connector with address null and port 9443# There is insufficient
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.