OutOfMemoryError in a separate Java thread

Note that I have a main Thread that launches a new Runnable in a new thread. Now that a new thread is running, the Java virtual machine has run out of memory and throws OutOfMemoryError.

What's happening? Does the target thread interrupt? Will the main thread continue? When a new thread crashes, will the VM return the memory from it and continue execution?

+5
source share
1 answer

One of the threads will throw OutOfMemoryErrorwhile the item is being selected new. To avoid interruptions, it is possible that after the error a significant amount of free memory will be freed. Thus, other threads can continue and are unlikely to be OOME for a certain period of time.

If OOME is not caught, the thread will exit and call the uncaught exception handler. Upon exit, the stream and its associated objects will be available for garbage collection, as usual (without reference in other ways).

+7
source

All Articles