Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Java's garbage collector interrupt a thread?

Something is interrupting threads in my application. It appears to happen when the JVM is close to running out of heap space. I can configure additional heap for the JVM but I'm curious if the garbage collector is interrupting threads in an attempt to reclaim memory. Does anyone know? I am using the 64 bit Java 1.6.0_16 on RedHat ES 5.2.

Thanks,

John

like image 951
John in MD Avatar asked Dec 12 '22 23:12

John in MD


2 Answers

Interrupt as in throw InterruptedException? No, that shouldn't happen. It may need to pause the thread itself, but that's not the same thing. If the VM runs out of memory completely, it should throw OutOfMemoryError instead...

like image 126
Jon Skeet Avatar answered Dec 24 '22 10:12

Jon Skeet


Unless OutOfMemory happens, Threads will not be interrupted if garbage collection happens. They may go in wait state for sometime.

like image 23
Fazal Avatar answered Dec 24 '22 11:12

Fazal