Home Answers Viewqa Java-Beginners Thread Memory Usage in java

 
 


guohualee
Thread Memory Usage in java
2 Answer(s)      5 years and a month ago
Posted in : Java Beginners

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 Pages:
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
Determining Memory Usage in Java - java tutorial
Determining Memory Usage in Java 2001-08-28 The Java Specialists' Newsletter [Issue 029] - Determining Memory Usage in Java Author: Dr. Heinz M. Kabutz.... Memory Usage in Java In Java, memory is allocated in various places
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 Get Memory Usage
Java Get Memory Usage     ... that in the given example code output.     Java Code to Get Memory Usage... Code For more details on memory usage, see the article on Memory Usage in 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
Out Of Memory Exception Erorr
Out Of Memory Exception Erorr  hello how are you?I hope you are fine I'm using jgrasp program my problem is in java programming my program compiled...: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main" I
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
memory management
memory management  memory management in java
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 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
Thread
Thread  Write a Java program to create three theads. Each thread should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread....   Java Thread Example class ThreadExample{ static int
Thread
Thread  Explain the use of throw and throws keywords.   Java throw and throws Whenever we want to force an exception then we use throw... a possible exception then we use throws keyword. Point to note here is that the Java
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism...:/www.roseindia.net/java/thread/index.shtml
Java memory leak
Java memory leak  What is memory leak
Exception Usage
Java NotesException Usage Exceptions Exception Usage | Exceptions - More Common Exceptions The most common exceptions to catch are number conversion...) { // Silently ignore. This thread can never cause an exception. } If you
Controlling Java Heap Size Memory Allocation
Controlling Java Heap Size Memory Allocation  Hi, Tell me about Controlling Java Heap Size Memory Allocation? I have to run java program from console and allocate 2GB of RAM to Java Heap Size. Thanks   Hi, You can
Thread Questions
Java NotesThread Questions Name _______________________________ Which areas of memory do separate threads share? Circle all that are correct. Call stack Heap Static memory They don't share any memory
Confuse about Quartz or Thread. - JSP-Servlet
process. In Java Programming language, thread is a sequential path of code... to : http://www.roseindia.net/quartz/ http://www.roseindia.net/java/thread...Confuse about Quartz or Thread.  Hi, Thanx for reply. Is it make
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
cpu usage spike for javaw.exe
. High CPU usage problem does not occur when I run other single java programs. I...cpu usage spike for javaw.exe  I have made a software/project as major project for college which involves 7 class files(.class) 122 Images and 1
Java memory allocation
Java memory allocation  How does Java allocate stack and heap memory
Overview of Thread
with this program. Thread A thread is a lightweight process which exist within... thread is referred to as a single-threaded process, while a process with multiple threads is referred to as a multi-threaded process. In Java
Memory - Java Beginners
Memory management in Java  Where are these Heap and Stack? Is there size fixed? what is core area in memory
JavaMail API usage - JavaMail
JavaMail API usage  Hello sir, i wrote a program to send a message from one mail account to another mail account,for that i uses JAVA and JSP two separate programes,but any one can send the mail.I did all the things required
java Thread
java Thread  what is purpose of Thread
Thread in java
Thread in java  which method will defined in thread class
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
memory
memory  what is memory
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
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
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 Get Memory
Java Get Memory       In this section of Java Example, you will see how to get the memory... can easily learn it. In this Java Get Memory Size example, we have created
Java read file in memory
Java read file in memory In this section, you will learn how to read a file in memory. Description of code: The class FileInputStream get a channel...++)); } System.out.println(); } } The above code mapped the file in a memory
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
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
JSF Datatable usage - Java Server Faces Questions
JSF Datatable usage  Hi, I am new to JSF. I need to display a Java List into a table with 4 columns.The List contains "String" values. Am using Datatable for the same, but am not able to figure out the solution. Can you
JSF Datatable usage - Java Server Faces Questions
JSF Datatable usage  Hi, I am new to JSF. I need to display a Java List into a table with 4 columns.The List contains "String" values. Am using Datatable for the same, but am not able to figure out the solution. Can you
Java thread
Java thread  Can we have run() method directly without start() method in threads
Thread scheduling
Thread scheduling  What is the algorithm used in Thread scheduling?  Java uses fixed-priority scheduling algorithms to decide which thread... is started, Java makes the lower priority thread wait if more than one thread exists
Demon thread
Demon thread  What is demon thread? why we need Demon thread?  ... there are daemon thread by killing them abruptly.Any thread can be a daemon thread. For more information, visit the following link: http://www.roseindia.net/java

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.