most of the time, I see this -- notice that the Joiner thread does not seem to get an interrupt
> java Test
both threads started
Starting oomer
Starting joiner
got exception from thread Thread[OOM thread,5,main]
java.lang.OutOfMemoryError: Java heap space
at Test$OOMer.run(Test.java:10)
at java.lang.Thread.run(Thread.java:745)
about to interrupt Thread[Joiner thread,5,main]
Successfully joined
but every once in a while (1/10 or so?), I see this:
> java Test
both threads started, main done
Starting joiner
Starting oomer
got exception from thread Thread[Thread-0,5,main]
java.lang.OutOfMemoryError: Java heap space
at Test$OOMer.run(Test.java:10)
at java.lang.Thread.run(Thread.java:745)
about to interrupt Thread[Thread-1,5,main]
interrupted!
got exception from thread Thread[Thread-1,5,main]
java.lang.RuntimeException: java.lang.InterruptedException
at Test$Joiner.run(Test.java:44)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Thread.join(Thread.java:1245)
at java.lang.Thread.join(Thread.java:1319)
at Test$Joiner.run(Test.java:40)
... 1 more
about to interrupt Thread[Thread-1,5,main]
I'm testing with:
> java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
you can loop like so:
> for i in `seq 1 10`;
do
java Test
done
If I run with -XX:OnOutOfMemoryError="kill -9 %p"
, then it consistently dies like this (doesn't finish join or interrupt):
> java -XX:OnOutOfMemoryError="kill -9 %p" Test
Starting joiner
Starting oomer
both threads started
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="kill -9 %p"
# Executing "kill -9 45102"...