-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8, 9
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
This is applicable for all windows platform JRE. I have tested this on windows 7 64 bit
Ver Output: W7-O-140123-072
A DESCRIPTION OF THE PROBLEM :
When you create a thread in java and use the Thread.sleep command, it creates a internal system event on windows but does not close the handle for the same. To capture the handle output I have used the "handle" utility provided by Microsoft which shows that after all the 3000 threads are there are 15000 odd event handles still open.
Download the handle utility from the following location
https://technet.microsoft.com/en-us/sysinternals/handle.aspx
If you update the run method with just a sysout instead of the sleep like below
@Override
public void run()
{
System.out.println(Thread.currentThread().getName() + " Done!");
}
it still leaks 1700 event handles.
These handles are not cleared even after garbage collection. Is this a bug or expected behavior ? Can these leaks cause the JVM to crash and go out of memory
REGRESSION. Last worked in version 8u72
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Download the attached java file
2. Download handle utility from (https://technet.microsoft.com/en-us/sysinternals/handle.aspx)
3. Compile the attached java file : javac TestThread.java
4. Run using java TestThread
5. Capture the process id from task manager (Say PID:1000)
6. Run the following command: handle.exe -s -p <<PID>>
7. The programs stops for 15 seconds to capture the handle output
8. Run the same command on step 6 after the program print GC Done. Current Active Thread Count 1
9. The event count does not match
7. Kill the program by using ctrl+C on the command prompt
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The handle if any are open should be closed after the thread has exited.
ACTUAL -
See a leak of 15000 odd thread event handles instead of none
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestThread
{
public static void main(String[] args)
{
try
{
Thread.sleep(15000);
}
catch (InterruptedException e)
{
}
for (int i = 0; i < 3000; i++)
{
MyThread thd = new MyThread();
thd.setName("DummyThd-"+Integer.toString(i));
thd.start();
}
System.out.println("Sleeping for 15 secs");
try
{
Thread.sleep(15000);
}
catch (InterruptedException e)
{
}
System.gc();
System.out.println("GC Done");
System.out.println("Current Active Thread Count " + Thread.activeCount());
Thread thd = new JustKeepRunning();
thd.start();
try
{
thd.join();
}
catch (InterruptedException e)
{
}
}
}
class MyThread extends Thread
{
@Override
public void run()
{
try
{
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName() + " Done!");
}
catch (InterruptedException e)
{
// do nothing
}
}
}
class JustKeepRunning extends Thread
{
@Override
public void run()
{
while (true)
{
try
{
Thread.sleep(500000);
System.out.println(Thread.currentThread().getName() + " Done!");
}
catch (InterruptedException e)
{
// do nothing
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
This is applicable for all windows platform JRE. I have tested this on windows 7 64 bit
Ver Output: W7-O-140123-072
A DESCRIPTION OF THE PROBLEM :
When you create a thread in java and use the Thread.sleep command, it creates a internal system event on windows but does not close the handle for the same. To capture the handle output I have used the "handle" utility provided by Microsoft which shows that after all the 3000 threads are there are 15000 odd event handles still open.
Download the handle utility from the following location
https://technet.microsoft.com/en-us/sysinternals/handle.aspx
If you update the run method with just a sysout instead of the sleep like below
@Override
public void run()
{
System.out.println(Thread.currentThread().getName() + " Done!");
}
it still leaks 1700 event handles.
These handles are not cleared even after garbage collection. Is this a bug or expected behavior ? Can these leaks cause the JVM to crash and go out of memory
REGRESSION. Last worked in version 8u72
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Download the attached java file
2. Download handle utility from (https://technet.microsoft.com/en-us/sysinternals/handle.aspx)
3. Compile the attached java file : javac TestThread.java
4. Run using java TestThread
5. Capture the process id from task manager (Say PID:1000)
6. Run the following command: handle.exe -s -p <<PID>>
7. The programs stops for 15 seconds to capture the handle output
8. Run the same command on step 6 after the program print GC Done. Current Active Thread Count 1
9. The event count does not match
7. Kill the program by using ctrl+C on the command prompt
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The handle if any are open should be closed after the thread has exited.
ACTUAL -
See a leak of 15000 odd thread event handles instead of none
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestThread
{
public static void main(String[] args)
{
try
{
Thread.sleep(15000);
}
catch (InterruptedException e)
{
}
for (int i = 0; i < 3000; i++)
{
MyThread thd = new MyThread();
thd.setName("DummyThd-"+Integer.toString(i));
thd.start();
}
System.out.println("Sleeping for 15 secs");
try
{
Thread.sleep(15000);
}
catch (InterruptedException e)
{
}
System.gc();
System.out.println("GC Done");
System.out.println("Current Active Thread Count " + Thread.activeCount());
Thread thd = new JustKeepRunning();
thd.start();
try
{
thd.join();
}
catch (InterruptedException e)
{
}
}
}
class MyThread extends Thread
{
@Override
public void run()
{
try
{
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName() + " Done!");
}
catch (InterruptedException e)
{
// do nothing
}
}
}
class JustKeepRunning extends Thread
{
@Override
public void run()
{
while (true)
{
try
{
Thread.sleep(500000);
System.out.println(Thread.currentThread().getName() + " Done!");
}
catch (InterruptedException e)
{
// do nothing
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.