I read about it in practice. Now I want to understand how to handleInterrruptedException
InterrruptedException
Tips from the book:
- throw an exception (perhaps after some cleaning of the task) which makes your method an intermittent method of blocking; or- restore the interrupt status so that the code above in the call stack can handle this.- only that implements a thread interrupt policy can internalize an interrupt request. Task and general purpose library code should never swallow interrupt requests.
The first two statements are clear to me, but I do not understand the third. Can you clarify this? Preferred example.
Once it’s acceptable to learn an interrupt when you know the thread is about to exit. This scenario only occurs when the interrupt method call class is part of a stream, not Runnable or general-purpose library code , as shown in Listing 5. This creates a stream that lists primes until it is interrupted and allows the stream break down. The prime minister loop checks for interruption in two places: once by polling isInterrupted () in the header of the while loop and once when he calls the blocking method BlockingQueue.put ().
public class PrimeProducer extends Thread { private final BlockingQueue<BigInteger> queue; PrimeProducer(BlockingQueue<BigInteger> queue) { this.queue = queue; } public void run() { try { BigInteger p = BigInteger.ONE; while (!Thread.currentThread().isInterrupted()) queue.put(p = p.nextProbablePrime()); } catch (InterruptedException consumed) { /* Allow thread to exit */ } } public void cancel() { interrupt(); } }
Now I do not understand the bold text.
ExecutorService will be an example of a third operator.
ExecutorService
runnables (/callables) "" .
runnable , runnables.
, ExecutorService , runnable, runnable.
, , - , . InterruptedException, ( try), , InterruptedException interrupt, true, interrupt.
InterruptedException
interrupt
, , InterruptedException []. InterruptedException , .
, - , . , .
: , .
, , , . , , , , "", .
. .
Source: https://habr.com/ru/post/1669666/More articles:SPSS: REPEAT with a different number of consistent variables - repeatHow to add a lot to a large number of records that have an extra column - ruby | fooobar.comWhat is the difference between DropDownList.ClearSelection () and DropDownList.SelectedIndex = -1 - c #Custom Playback Converter - playframeworktoo many redirects using filter class - jsfSocial network. Follow the functionality using the firebase database. - androidWhy are end variables in scala allowed to change values - scalaGradle построить на Дженкинс не удалось - javaМеню Hamburger Menu & Overflow продолжает исчезать - codenameoneUsing Firebase on iOS - iosAll Articles