finally will always be executed, except in rare situations.
In general, it is a guarantee that your code will free busy resources even if exceptions occur (
Exceptions ) or the method containing
try returns prematurely (
The only times that
If you call
finally will not be called are:
another thread interrupt the current one (via the
interrupt() method) or
If the JVM crash before.
According to Oracle Tutorials :
If the JVM exits while the try or catch code is being executed,
then the finally block may not execute. Likewise, if the thread
executing the try or catch code is interrupted or killed, the finally
block may not execute even though the application as a whole continues.
(Answer based on question 1 and StackOverflow question 2 .