文章预览
点击上方“ CSDN ”,选择“置顶公众号” 关键时刻,第一时间送达! 作者丨Igor Sorokin 译者 丨 Teixeira10 【译者注】 在本文中,作者总结出了5个关于处理并发性程序的技巧,并给出代码示例,让读者更好地理解和使用这5种方法。 以下为译文: 1. 捕获InterruptedException错误 请检查下面的代码片段: public class Task implements Runnable { private final BlockingQueue queue = ...; @Override public void run() { while (!Thread.currentThread().isInterrupted()) { String result = getOrDefault(() -> queue.poll(1L, TimeUnit.MINUTES), "default"); //do smth with the result } } T getOrDefault(Callable supplier, T defaultValue) { try { return supplier.call(); } catch (Exception e) { logger.error("Got exception while retri
………………………………