Вот код меня озадачил:
public Integer getInteger(BlockingQueue<Integer> queue) {
boolean interrupted = false;
try {
while (true) {
try {
return queue.take();
} catch (InterruptedException e) {
interrupted = true;
// fall through and retry
}
}
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
}
Кажется, что блок try не остановится из-за блока While(true), но мне сказали, что блок finally всегда будет выполняться после завершения блока try. Итак, когда будет выполняться блок finally?
finally
, если у вас действительно есть бесконечный цикл в блокеtry
. - person Tim Biegeleisen   schedule 22.10.2015