Solved

memory usage in a java program running on linux

Posted on 2006-07-17
6
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 77
iterator/ListIterator approach 17 55
Java string replace 11 64
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 47
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

730 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