Hi, we have the public recommendation in Oak not to use Thread.interrupt() [1]; this was caused by SLING-4477, where a different thread was interrupted, and caused repository issues. But in my opinion this statement is too generic, and for that is not really helpful. Because InterruptedExceptions are thrown at a number of places, and the default recommendation to handle this excception you you will always find "Call Thread.currentThread().interrupt()", so by reading that statement the naive way, you could understand that we recommend not to use the "standard way" to handle such exceptions.
Now, I do think, that "Thread.currentThread().interrupt()" is not a problem at all. Because the problem is only when the thread you want to interrupt is currently executing operations at that particular location in the Oak code. But when explicitly interrupt the current thread, it cannot execute that particular Oak code, because it is executing the interrupt() right now in the context of your code. So this execution is guaranteed to be safe in every context (unless you are dealing with NIO on your own, but that's a different story). For that I recommend change [1] in a way, that it explicitly mentions only code, which interrupts other threads (not the current thread), for example ExecutorService.shutdownNow(), which is documented to use Thread.interrupt() to force the shutdown of other threads in that executor. And we should explicitly mention the statement "Thread.currentThread().interrupt()" to be safe. WDYT? Jörg [1] https://jackrabbit.apache.org/oak/docs/dos_and_donts.html#Don.27t_use_Thread.interrupt.28.29 [2] https://issues.apache.org/jira/browse/SLING-4477 -- https://cqdump.joerghoh.de
