Thread Memory Usage in java



Share on Google+Share on Google+

Thread Memory Usage in java
2 Answer(s)      9 years ago
Posted in : Java Beginners
View Answers

May 8, 2008 at 6:28 PM

hi friend,

import java.util.*;
import java.util.logging.Logger;

public class ThreadMemory
implements Runnable{
public static Logger logger = Logger.getLogger(ThreadMemory.class.getName());

protected static Thread mainThread;
protected static int sleepSec;

public ThreadMemory() {
public ThreadMemory(int sleepSec)
this.sleepSec = sleepSec;

public static boolean isMonitorActive() {
return mainThread.isAlive();
return false;

public void startMonitor()
mainThread = new Thread(this, this.getClass().getName());

public void run(){"Started with polling = " + String.valueOf(sleepSec) + " sec");
while(true){"Free mem: " + String.valueOf(Runtime.getRuntime().freeMemory()));"Tot mem: " + String.valueOf(Runtime.getRuntime().totalMemory()));"Thread n: " + String.valueOf(Thread.currentThread().activeCount()));"");

// Sleeps (polling time):
try {

} catch (InterruptedException e){
System.out.println("errer threas sleeping"+ e);
} // end run

public static void main(String args[]){

ThreadMemory thread = new ThreadMemory();

System.out.println("Welcome roseindia");




read for more information,

May 9, 2008 at 12:26 PM

but,if I use G++ tools to compile a c++ program in a java thread,

as:Runtime.getRuntime().exe("g++ -o...*.cpp...");

Can this method work well for compute c++ program's memeory usage?

In other words,i want to compute a C++_program's memory usage in java,

Can I do it?


Related Tutorials/Questions & Answers:
Thread Memory Usage in java - Java Beginners
Thread Memory Usage in java  how to get a thread's memory usage? Does...://   but,if I use G++ tools to compile a c++ program in a java thread, as:Runtime.getRuntime
Java Get Memory Usage
Java Get Memory Usage   ...;How to find the Memory Usage in Java?": Java Code to Get Memory... For more details on memory usage, see the article on Memory Usage in Java
Get Usage Memory Example
Get Usage Memory Example     ... in understanding Get Usage Memory. The class Memory Usage include the main method... ( )  -  This method return you the total amount of memory that your java
Java memory optimization
Java memory optimization  When you think about optimization, what..., You can use memory dump and then analyze it to find the process/java code in your program which is using large amount of memory. Ideally java should garbage
Java memory leak
Java memory leak  What is memory leak
Creating a memory leak with Java
Creating a memory leak with Java  Creating a memory leak with Java
Java memory allocation
Java memory allocation  How does Java allocate stack and heap memory
Java Thread setName
Java Thread setName() method sets the new name to each Thread. It is used in both Thread class and Runnable interface. Name is also set by the string data used in the constructor. Java Thread setName Example public class
java Thread
java Thread  what is purpose of Thread
Memory - Java Beginners
Memory management in Java  Where are these Heap and Stack? Is there size fixed? what is core area in memory
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What are the high-level thread states
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Usage of Hash Code - Java Interview Questions
Usage of Hash Code  Dear sir, What is Hashcode in Java and What is its usage? Thanks and Regards M.KehtraBalan  Hi Friend, A hashCode is a way of computing a small (32-bit) numeric key from a long
memory  what is memory
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
Memory   what is the different between heap memory and stack memory ? please explain with example
Thread in java
Thread in java  which method will defined in thread class
memory   hi i am jane pls explain the difference between heap memory and stack memory
Java Memory Leak - Java Beginners
Java Memory Leak  I am having a memory leak in my java version of the game Snake. I have narrowed the exact step of when the program memory.... The actually object that's eating up my memory is an array of ints which grows
Java Memory allocation - Java Interview Questions
Java Memory allocation  By default what is the memory allocation size for a single class? How the memory is allocated? Based on what procedure
Java thread
Java thread  What is the use of serializable
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  Can we have run() method directly without start() method in threads
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism...:/
Java get Free Memory
Java get Free Memory       In this section, we are going to obtain the free memory. In order to get the memory left of being allocated, the method getruntime() returns
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017


Advertisement null