RSS feed [root] /concurrency /weblog /java



title search:


Sat Mar 19 23:00:19 AEDT 2022


Just know that interrupt() call is just setting a flag, it have to be doing IO work (like database call), or in wait() status, before the thread can really be interrupted.[..]winger?entry=swingworker_stop_that_train

Another nice explanation about interrupt, in summary:

What should we do when we call code that may cause an InterruptedException? Don't immediately yank out the batteries! Typically there are two answers to that question:
1) Rethrow the InterruptedException from your method. This is usually the easiest and best approach. It is used by the new java.util.concurrent.* package [[..]util/concurrent/Semaphore.html#acquire() ], which explains why we are now constantly coming into contact with this exception.
2) Catch it, set interrupted status, return. If you are running in a loop that calls code which may cause the exception, you should set the status back to being interrupted. For example:
while (!Thread.currentThread().isInterrupted()) {
// do something
try {
} catch (InterruptedException e) {
Remember the Law of the Sabotaged Doorbell - don't just ignore interruptions, manage them properly!


Another blog explain about InterruptedException -[..]terruptedexception-and-interrupting.html[..]running-infinite-java-regular-expression[..]derstanding-thread-interruption-in-java/

How to Stop a Java Thread Without Using Thread.stop()? -[..]a-java-thread-without-using-thread-stop/

(google search) (amazon search)
download zip of files only