Solved

memory usage in a java program running on linux

Posted on 2006-07-17
6
232 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB Script to add site to Java Exception List 4 78
Java exception bubble up 2 18
by zero exception 10 41
JAVA API design with micro service cloud in mind 1 18
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

803 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