Solved

memory usage in a java program running on linux

Posted on 2006-07-17
6
239 Views
Last Modified: 2012-05-05
I have a very simple Java program running in linux:

public class test
{

    public test()
    {}

    public static void main(String[] args)
    {
      test t1 = new test();
      t1.begin();
    }

    public void begin()
    {
       while(true)
       {
           try
           {
                System.out.println("one iteration");
                Thread.sleep(5*60*1000);
           }
           catch(Exception ex)
           { ex.printStackTrace(); }
        }
     }
}

What is the best way to find the memory used by this process in linux.

I am using the jvm property (-mx3000000) to cap the maximum memory usage to 3MB. which means that if the jvm uses more than 3MB it would throw outOfMemoryError.
I have tried to monitor this process using the JConsole and the memory does not exceed the 3MB limit.

I am aware of two commands : top and pmap

if I use the top command it shows that the process using 23 MB

and pmap command (which can be used to view the private bytes ) shows that the process is using 123 MB.
(this is just the writable/private bytes)

I am new to linux. Can anyone please explain that if the jvm property forces the process to terminate  if it uses more than the assigned memory (max memory), where do I find the explanation for the remaining memory usage.





0
Comment
Question by:rnicholus
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 168 total points
ID: 17126514
you're only limiting the amount of heap available in the jvm, yoiu are not limiting the amount of memory the vm takes from the OS
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 166 total points
ID: 17127465
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 166 total points
ID: 17128456
0
 

Author Comment

by:rnicholus
ID: 17129837
Thank you. I will try to use the memory profiler.

freeMemory() and totalMemory() methods from the Runtime class also account for the heap and not the total memory
used by the process.


0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 62
expectj telnet failing 5 45
Convert from a json string array to a Java object 3 53
Which non-HTML GUI front end to use with Java? 3 24
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question