RSS feed [root] /weblog /concurrency /java




login:

password:

title search:




 


Sat Mar 19 12:00:19 GMT 2022

Interrupt



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.

http://blogs.sun.com[..]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 [ http://java.sun.com[..]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 {
TimeUnit.SECONDS.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
Remember the Law of the Sabotaged Doorbell - don't just ignore interruptions, manage them properly!

- http://www.javaspecialists.eu/archive/Issue146.html

Another blog explain about InterruptedException - http://www.nurkiewicz.com[..]terruptedexception-and-interrupting.html

http://ocpsoft.org[..]running-infinite-java-regular-expression

http://praveer09.github.io[..]derstanding-thread-interruption-in-java/

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


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