注释的翻译如下:先interrupt所有的线程,在join它们,如果interrupted,就返回false,表明某些线程还在running
/**
* Try to interrupt all of the given threads, and join on them.
* If interrupted, returns false, indicating some threads may
* still be running.
*/
private boolean interruptAndJoinThreads(List<Thread> threads) {
// interrupt and wait for all ongoing create threads
for(Thread t : threads) {
t.interrupt();
}
for(Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
DataNode.LOG.warn("interruptOngoingCreates: t=" + t, e);
return false;
}
}
return true;
}
看一看thread的interrupt函数,从注释上看,如果interrupt还没结束就返回join,就会抛出InterruptedException
/**
* Interrupts this thread.
*
* <p> Unless the current thread is interrupting itself, which is
* always permitted, the {@link #checkAccess() checkAccess} method
* of this thread is invoked, which may cause a {@link
* SecurityException} to be thrown.
*
* <p> If this thread is blocked in an invocation of the {@link
* Object#wait() wait()}, {@link Object#wait(long) wait(long)}, or {@link
* Object#wait(long, int) wait(long, int)} methods of the {@link Object}
* class, or of the {@link #join()}, {@link #join(long)}, {@link
* #join(long, int)}, {@link #sleep(long)}, or {@link #sleep(long, int)},
* methods of this class, then its interrupt status will be cleared and it
* will receive an {@link InterruptedException}.
*
* <p> If this thread is blocked in an I/O operation upon an {@link
* java.nio.channels.InterruptibleChannel </code>interruptible
* channel<code>} then the channel will be closed, the thread's interrupt
* status will be set, and the thread will receive a {@link
* java.nio.channels.ClosedByInterruptException}.
*
* <p> If this thread is blocked in a {@link java.nio.channels.Selector}
* then the thread's interrupt status will be set and it will return
* immediately from the selection operation, possibly with a non-zero
* value, just as if the selector's {@link
* java.nio.channels.Selector#wakeup wakeup} method were invoked.
*
* <p> If none of the previous conditions hold then this thread's interrupt
* status will be set. </p>
*
* <p> Interrupting a thread that is not alive need not have any effect.
*
* @throws SecurityException
* if the current thread cannot modify this thread
*
* @revised 6.0
* @spec JSR-51
*/
public void interrupt() {
if (this != Thread.currentThread())
checkAccess();
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
interrupt0(); // Just to set the interrupt flag
b.interrupt();
return;
}
}
interrupt0();
}
分享到:
相关推荐
Hadoop源代码分析完整版.pdf Hadoop源代码分析 hadoop mapreduce
hadoop源代码存档
深入云计算:Hadoop源代码分析(修订版)
Hadoop源代码eclipse编译指南 Hadoop源代码eclipse编译指南
Hadoop源代码分析(完整版).pdf
Hadoop 源代码分析 完整版
Hadoop的源代码分析
Hadoop源代码分析 分析了hadoop的一些包,一些类 ,需要对hadoop深入了解的可以看看
大数据处理系统:Hadoop源代码情景分析(采用Hadoop 2.6)
Hadoop源代码分析完整版.pdf
资源名称:大数据处理系统:Hadoop源代码情景分析内容简介:Hadoop是目前重要的一种开源的大数据处理平台,读懂Hadoop的源代码,深入理解其各种机理,对于掌握大数据处理的技术有着显而易见的重要性。 本书从大数据...
进军Hadoop源代码,进军Hadoop源代码,进军Hadoop源代码,进军Hadoop源代码
Hadoop分析气象数据完整版源代码(含Hadoop的MapReduce代码和SSM框架) 《分布式》布置了一道小作业,这是作业的所有代码,里面包含了Hadoop的MapReduce代码、和SSM框架显示数据的代码
Hadoop源代码eclipse编译教程
包mapreduce.lib.map的Hadoop源代码分析
hadoop源码,官方,放心下载,完整版,阅读hadoop源代码的目的不一定非是工作的需要,你可以把他看成一种修养,通过阅读hadoop源代码,加深自己对分布式系统的理解,培养自己踏实做事的心态。
Task的内部类和辅助类的Hadoop源代码分析