You are still in the while loop, adding a break or some other way out of the loop.
catch (InterruptedException e) { System.out.println("interrupted"); break; }
Threading in Java is a kind of collaboration, you were asked to stop, but you need to be polite enough to actually do it. This allows the flow time to cleanse its affairs before its death.
As explained in detail by Simon and Amir, the condition for ending the cycle is surprisingly not enough.
source share