Thread Memory Usage in java

Thread Memory Usage in java

View Answers

May 8, 2008 at 6:28 PM

hi friend,

import java.io.*;
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() {
this(60);
}
public ThreadMemory(int sleepSec)
{
this.sleepSec = sleepSec;
}

public static boolean isMonitorActive() {
if(mainThread!=null)
return mainThread.isAlive();
else
return false;
}

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

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

// Sleeps (polling time):
try {
Thread.currentThread().sleep(sleepSec*1000);

} 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,

http://www.roseindia.net/java/thread/thread-creation.shtml


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...://www.roseindia.net/java/thread/thread-creation.shtml   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   ... tutorial of "How to find the Memory Usage in Java?": Java... usage, see the article on Memory Usage in Java
Advertisements
ModuleNotFoundError: No module named 'memory_usage_notifier'
ModuleNotFoundError: No module named 'memory_usage_notifier'  Hi...: No module named 'memory_usage_notifier' How to remove the ModuleNotFoundError: No module named 'memory_usage_notifier' error? Thanks   Hi
ModuleNotFoundError: No module named 'memory_usage_notifier'
ModuleNotFoundError: No module named 'memory_usage_notifier'  Hi...: No module named 'memory_usage_notifier' How to remove the ModuleNotFoundError: No module named 'memory_usage_notifier' error? Thanks   Hi
ModuleNotFoundError: No module named 'ipython-memory-usage'
ModuleNotFoundError: No module named 'ipython-memory-usage'  Hi...: No module named 'ipython-memory-usage' How to remove the ModuleNotFoundError: No module named 'ipython-memory-usage' error? Thanks   Hi
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 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 memory leak
Java memory leak  What is memory leak
java Thread
java Thread  what is purpose of Thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What are the high-level thread states
Creating a memory leak with Java
Creating a memory leak with Java  Creating a memory leak with Java
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
Thread in java
Thread in java  which method will defined in thread class
Java memory allocation
Java memory allocation  How does Java allocate stack and heap memory
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism... more at: http:/www.roseindia.net/java/thread/index.shtmlADS_TO_REPLACE_2
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link...({});   Hi, There are two types of Thread used in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference
Thread - Java Beginners
the concept of thread, thread creation and use of threads in JAVA application?  Thread creation and use of threads in JAVA Java Resourcehttp://www.roseindia.net/java/thread/thread-creation.shtml
Java thread state
Java thread state  what is Static binding
memory
memory  what is memory
There is insufficient memory for the Java Runtime Environment to continue.
There is insufficient memory for the Java Runtime Environment to continue.  Hi, I am getting error "There is insufficient memory for the Java...) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
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  What is the use of serializable
Java thread
Java thread  What is the difference between wait() and sleep method
Java thread
Java thread  What method must be implemented by all threads
Java thread
Java thread  Can we have run() method directly without start() method in threads
Memory
Memory   what is the different between heap memory and stack memory ? please explain with example
thread - Java Beginners
thread  can i asko for programs in thread method that will allow user to input two separate names  Hi friend, For more information on Thread visit to : http://www.roseindia.net/java/thread/index.shtml Thanks
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
Java thread state
Java thread state  What is the difference between yielding and sleeping
Java thread state
Java thread state  Difference between sleep and suspend
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
Thread and Process - Java Beginners
Thread and Process  Dear Deepak Sir, What is the diffrence between Thread and Process.Give an example with explanation. Thnaks & Regards.... In most multithreading operating systems, a process gets its own memory address
Daemon thread - Java Beginners
information, visit the following link: http://www.roseindia.net/java/thread...Daemon thread  Hi, What is a daemon thread? Please provide me... thread which run in background. like garbadge collection thread. Thanks 
memory
memory   hi i am jane pls explain the difference between heap memory and stack memory
Java Thread
Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple threads for concurrent execution. Each thread has priority. You can also set
Java Sleep Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
Java Thread
Java Thread Tutorials In this tutorial we will learn java Threads in detail. The Java Thread class helps the programmer to develop the threaded application in Java. Thread is simple path of execution of a program. The Java Virtual Machine
Java :Thread getPriority Example
Java :Thread getPriority Example In this tutorial you will learn how to get thread priority in java thread. Thread getPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
Thread
Thread  What is multi-threading? Explain different states of a thread.   Java Multithreading Multithreading is a technique that allows... processor system. States of Thread: New state ? After the creations of Thread
Java :Thread setPriority Example
Java :Thread setPriority Example In this tutorial you will learn how to set thread priority in java thread. Thread setPriority() : Thread scheduler uses thread priority concept to assign priority to the thread. A higher priority 
Extending thread - Java Beginners
visit to : http://www.roseindia.net/java/thread/index.shtml Thanks...Extending thread  what is a thread & give me the programm of exeucte the thread   Hi friend, Thread : A thread is a lightweight

Ads