Cust states:
"If I run the following code on Windows 95 and the latest
version of the JDK 1.1.1, the java virtual machine eventually
hangs. It always appears to hang when garbage collection
runs. To make the problem appear quickly, run the code as
written (java -verbosegc ThreadTest).
However, the problem will also appear more slowly
(within an hour rather than within minutes) when garbage
collection runs asynchronously if you comment out the last
line of code where System.gc() is called.
Here is the test program that causes the problem:
import java.util.*;
public class ThreadTest extends Thread
{
int count = 0;
Random randnum = new Random(System.currentTimeMillis());
public static void main (String[] args)
{
for (int i=0; i<100; i++)
{
ThreadTest foo = new ThreadTest(i);
foo.start();
}
}
public ThreadTest(int i)
{
count = i;
}
public void run()
{
for (;;)
{
int ttw = (Math.abs(randnum.nextInt()) % 1000) + 5;
byte [] wilma = new byte[Math.abs(randnum.nextInt()) % 5000];
synchronized(this)
{
System.out.println("Thread " + count + " waiting for " + ttw);
try { wait(ttw); } catch (Exception e) { e.printStackTrace(); }
}
wilma = null;
if ((ttw % 7) == 0) System.gc();
}
}
}
When I run with the last line commented (asynchronous gc)
and -verbosegc entered on the java command line, the last
thing I see is part of the normal output of garbage
collection, as follows:
<GC: managing allocation failure. need 4488 bytes, type=1, action=1>
Please let me know (by phone or e-mail) if there is something
wrong with the test program or when a fix is available.
"If I run the following code on Windows 95 and the latest
version of the JDK 1.1.1, the java virtual machine eventually
hangs. It always appears to hang when garbage collection
runs. To make the problem appear quickly, run the code as
written (java -verbosegc ThreadTest).
However, the problem will also appear more slowly
(within an hour rather than within minutes) when garbage
collection runs asynchronously if you comment out the last
line of code where System.gc() is called.
Here is the test program that causes the problem:
import java.util.*;
public class ThreadTest extends Thread
{
int count = 0;
Random randnum = new Random(System.currentTimeMillis());
public static void main (String[] args)
{
for (int i=0; i<100; i++)
{
ThreadTest foo = new ThreadTest(i);
foo.start();
}
}
public ThreadTest(int i)
{
count = i;
}
public void run()
{
for (;;)
{
int ttw = (Math.abs(randnum.nextInt()) % 1000) + 5;
byte [] wilma = new byte[Math.abs(randnum.nextInt()) % 5000];
synchronized(this)
{
System.out.println("Thread " + count + " waiting for " + ttw);
try { wait(ttw); } catch (Exception e) { e.printStackTrace(); }
}
wilma = null;
if ((ttw % 7) == 0) System.gc();
}
}
}
When I run with the last line commented (asynchronous gc)
and -verbosegc entered on the java command line, the last
thing I see is part of the normal output of garbage
collection, as follows:
<GC: managing allocation failure. need 4488 bytes, type=1, action=1>
Please let me know (by phone or e-mail) if there is something
wrong with the test program or when a fix is available.