we will break out of the loop. You might argue that we should logInterruptedException’s stack-trace. This depends on the situation, as in this case interrupting a thread is something we really expect, not a failure. But it’s up to you. The bottom-line is that ifsleep()is interrupted...
Notice thattry-catchblock now surroundswhileloop. This way ifsleep()throwsInterruptedException, we will break out of the loop. You might argue that we should logInterruptedException‘s stack-trace. This depends on the situation, as in this case interrupting a thread is something we really expect...
_ThreadID=118;_ThreadName=Thread-2; Record Number 328 Message ID Complete Message java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29) at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:69) at s...
Interrupting a Thread in JavaA thread can send an interrupt signal to JVM to interrupt by invoking interrupt on the Thread object for the thread to be interrupted. This means interruption of a thread is caused by any other thread calling the interrupt() method....