threadpoolexecutor.html

来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,102 行 · 第 1/5 页

HTML
1,102
字号
     try {       isPaused = false;       unpaused.signalAll();     } finally {       pauseLock.unlock();     }   } } </pre><P><P><DL><DT><B>从以下版本开始:</B></DT>  <DD>1.5</DD></DL><HR><P><!-- ======== NESTED CLASS SUMMARY ======== --><A NAME="nested_class_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>嵌套类摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;class</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.AbortPolicy.html" title="java.util.concurrent 中的类">ThreadPoolExecutor.AbortPolicy</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用于被拒绝任务的处理程序,它将抛出 <tt>RejectedExecutionException</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;class</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.CallerRunsPolicy.html" title="java.util.concurrent 中的类">ThreadPoolExecutor.CallerRunsPolicy</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用于被拒绝任务的处理程序,它直接在 <tt>execute</tt> 方法的调用线程中运行被拒绝的任务;如果执行程序已关闭,则会丢弃该任务。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;class</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.DiscardOldestPolicy.html" title="java.util.concurrent 中的类">ThreadPoolExecutor.DiscardOldestPolicy</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用于被拒绝任务的处理程序,它放弃最旧的未处理请求,然后重试 <tt>execute</tt>;如果执行程序已关闭,则会丢弃该任务。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;class</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.DiscardPolicy.html" title="java.util.concurrent 中的类">ThreadPoolExecutor.DiscardPolicy</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用于被拒绝任务的处理程序,默认情况下它将放弃被拒绝的任务。</TD></TR></TABLE>&nbsp;<!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>构造方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="ThreadPoolExecutor.html#ThreadPoolExecutor(int, int, long, java.util.concurrent.TimeUnit, java.util.concurrent.BlockingQueue)">ThreadPoolExecutor</A></B>(int&nbsp;corePoolSize,                   int&nbsp;maximumPoolSize,                   long&nbsp;keepAliveTime,                   <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit,                   <A HREF="BlockingQueue.html" title="java.util.concurrent 中的接口">BlockingQueue</A>&lt;<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&gt;&nbsp;workQueue)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用给定的初始参数和默认的线程工厂及处理程序创建新的 <tt>ThreadPoolExecutor</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="ThreadPoolExecutor.html#ThreadPoolExecutor(int, int, long, java.util.concurrent.TimeUnit, java.util.0AC32E6979">ThreadPoolExecutor</A></B>(int&nbsp;corePoolSize,                   int&nbsp;maximumPoolSize,                   long&nbsp;keepAliveTime,                   <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit,                   <A HREF="BlockingQueue.html" title="java.util.concurrent 中的接口">BlockingQueue</A>&lt;<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&gt;&nbsp;workQueue,                   <A HREF="RejectedExecutionHandler.html" title="java.util.concurrent 中的接口">RejectedExecutionHandler</A>&nbsp;handler)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用给定的初始参数创建新的 <tt>ThreadPoolExecutor</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="ThreadPoolExecutor.html#ThreadPoolExecutor(int, int, long, java.util.concurrent.TimeUnit, java.util.047F6FC9F1">ThreadPoolExecutor</A></B>(int&nbsp;corePoolSize,                   int&nbsp;maximumPoolSize,                   long&nbsp;keepAliveTime,                   <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit,                   <A HREF="BlockingQueue.html" title="java.util.concurrent 中的接口">BlockingQueue</A>&lt;<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&gt;&nbsp;workQueue,                   <A HREF="ThreadFactory.html" title="java.util.concurrent 中的接口">ThreadFactory</A>&nbsp;threadFactory)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用给定的初始参数创建新的 <tt>ThreadPoolExecutor</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="ThreadPoolExecutor.html#ThreadPoolExecutor(int, int, long, java.util.concurrent.TimeUnit, java.util.0617778962">ThreadPoolExecutor</A></B>(int&nbsp;corePoolSize,                   int&nbsp;maximumPoolSize,                   long&nbsp;keepAliveTime,                   <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit,                   <A HREF="BlockingQueue.html" title="java.util.concurrent 中的接口">BlockingQueue</A>&lt;<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&gt;&nbsp;workQueue,                   <A HREF="ThreadFactory.html" title="java.util.concurrent 中的接口">ThreadFactory</A>&nbsp;threadFactory,                   <A HREF="RejectedExecutionHandler.html" title="java.util.concurrent 中的接口">RejectedExecutionHandler</A>&nbsp;handler)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用给定的初始参数创建新的 <tt>ThreadPoolExecutor</tt>。</TD></TR></TABLE>&nbsp;<!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected &nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#afterExecute(java.lang.Runnable, java.lang.Throwable)">afterExecute</A></B>(<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&nbsp;r,             <A HREF="../../lang/Throwable.html" title="java.lang 中的类">Throwable</A>&nbsp;t)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;基于完成执行给定 Runnable 所调用的方法。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;boolean</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#awaitTermination(long, java.util.concurrent.TimeUnit)">awaitTermination</A></B>(long&nbsp;timeout,                 <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请求关闭、发生超时或者当前线程中断,无论哪一个首先发生之后,都将导致阻塞,直到所有任务完成执行。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected &nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#beforeExecute(java.lang.Thread, java.lang.Runnable)">beforeExecute</A></B>(<A HREF="../../lang/Thread.html" title="java.lang 中的类">Thread</A>&nbsp;t,              <A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&nbsp;r)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在执行给定线程中的给定 Runnable 之前调用的方法。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#execute(java.lang.Runnable)">execute</A></B>(<A HREF="../../lang/Runnable.html" title="java.lang 中的接口">Runnable</A>&nbsp;command)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在将来某个时间执行给定任务。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected &nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#finalize()">finalize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当不再引用此执行程序时,调用 <tt>shutdown</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getActiveCount()">getActiveCount</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回主动执行任务的近似线程数。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getCompletedTaskCount()">getCompletedTaskCount</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回已完成执行的近似任务总数。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getCorePoolSize()">getCorePoolSize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回核心线程数。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getKeepAliveTime(java.util.concurrent.TimeUnit)">getKeepAliveTime</A></B>(<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回线程保持活动的时间,该时间就是超过核心池大小的线程可以在终止前保持空闲的时间值。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getLargestPoolSize()">getLargestPoolSize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回曾经同时位于池中的最大线程数。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getMaximumPoolSize()">getMaximumPoolSize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回允许的最大线程数。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;int</CODE></FONT></TD><TD><CODE><B><A HREF="ThreadPoolExecutor.html#getPoolSize()">getPoolSize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回池中的当前线程数。</TD>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?