Article ID: 191933
Article Last Modified on 8/25/2005
import java.lang.Runtime;
import java.util.Vector;
class memtest implements Runnable{
private Vector v = new Vector();
private int nextThread = 1;
memtest ()
{
}
public synchronized int getThreadNo()
{
return nextThread++;
}
public void run()
{
int threadNo = getThreadNo();
Runtime rt = Runtime.getRuntime();
for (int i=0;;i++)
{
long freeMem = rt.freeMemory();
long totalMem = rt.totalMemory();
System.out.println( "Thread: " + threadNo
+ ", Iteration: " + i
+ ", Free Memory: " + freeMem
+ ", Total Memory: " + totalMem);
String s = new String("");
for (int j = 0; j < 1000; j++)
{
s = s + ".";
}
try
{
Thread.sleep(1000);
}
catch (Exception ex)
{
}
}}
public void _main()
{
for (int i = 0; i < 100; i++)
{
Thread t = new Thread(this);
v.addElement(t);
t.start();
try
{
Thread.sleep(100);
}
catch (Exception ex)
{
}
}
}
public static void main( String [] args )
{
memtest b = new memtest();
b._main();
}
}
Compile the above code. Open a console window and run JVIEW test > nul
Keywords: kbbug kbfix kbjava KB191933