ThreadPoolExecutor

本文详细介绍了Java线程池ThreadPoolExecutor的核心概念、参数设置、执行流程以及常见策略,帮助开发者更好地理解并利用线程池提高应用性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.util.concurrent
类<wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">ThreadPoolExecutor</span><wbr style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> java.lang.Object<br style="line-height:25px"> 继承者java.util.concurrent.AbstractExecutorService<br style="line-height:25px"> 继承者java.util.concurrent.ThreadPoolExecutor<br style="line-height:25px"> 所有已实现的接口:<br style="line-height:25px"> Executor,<span style="line-height:25px"><span style="color:#ff9900; line-height:25px"><wbr style="line-height:25px">ExecutorService</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"> 直接已知子类:<br style="line-height:25px"><del style="line-height:25px"></del><wbr style="line-height:25px"><span style="color:#ff9900; line-height:25px">ScheduledThreadPoolExecutor</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px; color:rgb(255,0,255)">ThreadPoolExecutor</span>是<span style="color:#ff9900; line-height:25px">ExecutorService</span>的一个实现类,它使用可能的几个池线程之一执行每个提交的任务,通常使用Executors工厂方法配置。<br style="line-height:25px"><wbr style="line-height:25px">线程池可以解决两个不同问题:由于减少了每个任务调用的开销,它们通常可以在执行大量异步任务时提供增强的性能,并且还可以提供绑定和管理资源(包括执行任务集时使用的线程)的方法<wbr style="line-height:25px">。<br style="line-height:25px"> 每个<span style="color:#ff00ff; line-height:25px">ThreadPoolExecutor</span>还维护着一些基本的统计数据,如完成的任务数。为了便于跨大量上下文使用,此类提供了很多可调整的参数和扩展钩子(hook)。<br style="line-height:25px"> 但是,强烈建议程序员使用较为方便的Executors工厂方法<span style="color:#0000ff; line-height:25px">Executors.<wbr style="line-height:25px">newCachedThreadPool<wbr style="line-height:25px">()</wbr></wbr></span>(<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">无界线程池,可以进行自动线程回收</span><wbr style="line-height:25px">)、<span style="color:#0000ff; line-height:25px">Executors.newFixedThreadPool(int)</span>(<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">固定大小线程池</span><wbr style="line-height:25px">)和<span style="color:#0000ff; line-height:25px">Executors.newSingleThreadExecutor()</span>(<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">单个后台线程</span><wbr style="line-height:25px">),<br style="line-height:25px"> 它们均为大多数使用场景预定义了设置。否则,在手动配置和调整此类时,使用以下指导:<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">核心和最大池大小</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">ThreadPoolExecutor</span>将根据<span style="color:#99cc00; line-height:25px">corePoolSize</span>(参见getCorePoolSize())和<span style="color:#808000; line-height:25px">maximumPoolSize</span>(参见getMaximumPoolSize())<br style="line-height:25px"> 设置的边界自动调整池大小。<span style="color:#000080; line-height:25px">当新任务在方法</span><span style="color:#0000ff; line-height:25px">execute(java.lang.Runnable)</span><span style="color:#000080; line-height:25px">中提交时,如果运行的线程少于</span><span style="color:#99cc00; line-height:25px">corePoolSize</span><span style="color:#000080; line-height:25px">,则创建新线程来处理请求,即使有线程是空闲的。</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">如果运行的线程多于</span><span style="color:#99cc00; line-height:25px">corePoolSize</span><span style="color:#003366; line-height:25px">而少于</span><span style="color:#808000; line-height:25px">maximumPoolSiz</span><span style="color:#003366; line-height:25px">e,则仅当队列满时才创建新线程。<br style="line-height:25px"> 如果设置的</span><span style="color:#99cc00; line-height:25px">corePoolSize</span><span style="color:#003366; line-height:25px">和</span><span style="color:#808000; line-height:25px">maximumPoolSize</span><span style="color:#003366; line-height:25px">相同,则创建了固定大小的线程池。<br style="line-height:25px"> 如果将</span><span style="color:#808000; line-height:25px">maximumPoolSize</span><span style="color:#003366; line-height:25px">设置为基本的无界值(如</span>Integer.MAX_VALUE<span style="color:#003366; line-height:25px">),则允许池适应任意数量的并发任务。<br style="line-height:25px"> 在大多数情况下,核心和最大池大小仅基于构造来设置,不过也可以使用</span><span style="color:#0000ff; line-height:25px">setCorePoolSize(int)</span><span style="color:#003366; line-height:25px">和</span><span style="color:#0000ff; line-height:25px">setMaximumPoolSize(int)</span><span style="color:#003366; line-height:25px">进行动态更改。</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:在新任务被提交时,如果运行的core线程少于corePoolSize,才创建新core线程。并不是一开始就创建corePoolSize个core线程。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">2:"如果运行的线程多于corePoolSize而少于maximumPoolSize,则仅当队列满时才创建新线程"<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">按需构造</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"> 核心线程最初只是在新任务到达时才被ThreadPoolExecutor创建和启动的,<br style="line-height:25px"> 但是<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">也可以手动调用方法</span><span style="color:#339966; line-height:25px">prestartCoreThread()</span><span style="color:#000080; line-height:25px">或</span><span style="color:#808000; line-height:25px">prestartAllCoreThreads()</span><span style="color:#000080; line-height:25px">来的提前启动核心线程<wbr style="line-height:25px">。</wbr></span><br style="line-height:25px"> 如果构造带有非空队列的池,这时则可能希望预先启动线程。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:核心线程即core线程,只有当前线程数小于等于corePoolSize时,这时的线程才叫核心线程。<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">创建新线程</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#003366; line-height:25px">使用</span><span style="color:#ff00ff; line-height:25px">ThreadFactory</span><span style="color:#003366; line-height:25px">创建新线程。如果没有另外说明,则使用</span><span style="color:#0000ff; line-height:25px">Executors.defaultThreadFactory()</span><span style="color:#003366; line-height:25px">创建线程,他们在同一个ThreadGroup中<br style="line-height:25px"> 并且这些线程具有相同的NORM_PRIORITY优先级和非守护进程状态。</span><br style="line-height:25px"> 通过提供不同的ThreadFactory,可以改变线程的名称、线程组、优先级、守护进程状态,等等。<br style="line-height:25px"> 如果从newThread返回null时ThreadFactory未能创建线程,则执行程序将继续运行,但不能执行任何任务。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:可以指定创建线程的ThreadFactory,默认的是使用Executors.defaultThreadFactory()来创建线程,所有的线程都在一个ThreadGroup中。<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">保持活动时间</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#003366; line-height:25px">如果池中当前有多于corePoolSize的线程,则这些多出的线程在空闲时间超过keepAliveTime时将会终止<br style="line-height:25px"> (参见</span><span style="color:#0000ff; line-height:25px">getKeepAliveTime(java.util.concurrent.TimeUnit)</span><span style="color:#003366; line-height:25px">)。这提供了当池处于非活动状态时减少资源消耗的方法。<br style="line-height:25px"> 如果池后来变得更为活动,则可以创建新的线程。也可以使用方法setKeepAliveTime(long,java.util.concurrent.TimeUnit)动态地更改此参数。</span><br style="line-height:25px"> 如果把值设为<span style="color:#0000ff; line-height:25px">Long.MAX_VALUETimeUnit.NANOSECONDS</span>的话,<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">空闲线程不会被回收</span><wbr style="line-height:25px">直到ThreadPoolExecutor为Terminate。<br style="line-height:25px"> 默认情况下,保持活动策略只在有多于corePoolSizeThreads的线程时应用。<br style="line-height:25px"> 但是只要keepAliveTime值非0,<span style="color:#0000ff; line-height:25px">allowCoreThreadTimeOut(boolean)</span>方法也可将此超时策略应用于核心线程。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:setKeepAliveTime(long,java.util.concurrent.TimeUnit)用于设置空闲线程最长的活动时间,<br style="line-height:25px"> 即如果空闲时间超过设定值,就停掉该线程,对该线程进行回收。<br style="line-height:25px"> 该策略默认只对非内核线程有用(即当前线程数大于corePoolSize),<br style="line-height:25px"> 可以调用allowCoreThreadTimeOut(boolean)方法将此超时策略扩大到核心线程<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">2:如果把值设为Long.MAX_VALUETimeUnit.NANOSECONDS的话,空闲线程不会被回收直到ThreadPoolExecutor为Terminate。<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">排队</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"> 所有<span style="color:#ff6600; line-height:25px">BlockingQueue</span>都可用于传输和保持提交的任务。可以使用此队列与池大小进行交互:<br style="line-height:25px"><span style="color:#000080; line-height:25px">*如果运行的线程少于corePoolSize,则Executor始终首选添加新的线程,而不进行排队。<br style="line-height:25px"> *如果运行的线程等于或多于corePoolSize,则Executor始终首选将请求加入队列,而不添加新的线程。<br style="line-height:25px"> *如果无法将请求加入队列,则创建新的线程,除非创建此线程超出maximumPoolSize,在这种情况下,任务将被拒绝</span>。<br style="line-height:25px"> 排队有三种通用策略:<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">1.直接提交</wbr></span><wbr style="line-height:25px">。工作队列的默认选项是SynchronousQueue,它将任务直接提交给线程而不保持它们。<br style="line-height:25px"> 在此,如果不存在可用于立即运行任务的线程,则试图把任务加入队列将失败,因此会构造一个新的线程。<br style="line-height:25px"> 此策略可以避免在处理可能具有内部依赖性的请求集时出现锁。<br style="line-height:25px"> 直接提交通常要求无界maximumPoolSizes以避免拒绝新提交的任务。<br style="line-height:25px"> 当命令以超过队列所能处理的平均数连续到达时,此策略允许线程无界的增长。<br style="line-height:25px"><span style="line-height:25px">注意1</span>:此策略允许线程无界的增长。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">2.无界队列</wbr></span><wbr style="line-height:25px">。使用无界队列(例如,不具有预定义容量的LinkedBlockingQueue)将导致在所有corePoolSize线程都忙时新任务在队列中等待。<br style="line-height:25px"> 这样,创建的线程就不会超过corePoolSize。(因此,maximumPoolSize的值也就无效了。)<br style="line-height:25px"> 当每个任务完全独立于其他任务,即任务执行互不影响时,适合于使用无界队列;例如,在Web页服务器中。<br style="line-height:25px"> 这种排队可用于处理瞬态突发请求,当命令以超过队列所能处理的平均数连续到达时,此策略允许队列无限的增长。<br style="line-height:25px"> 注意1:此策略允许队列无限的增长。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">3.有界队列</wbr></span><wbr style="line-height:25px">。当使用有限的maximumPoolSizes时,有界队列(如ArrayBlockingQueue)有助于防止资源耗尽,但是可能较难调整和控制。<br style="line-height:25px"> 队列大小和最大池大小可能需要相互折衷:使用大型队列和小型池可以最大限度地降低CPU使用率、操作系统资源和上下文切换开销,<br style="line-height:25px"> 但是可能导致人工降低吞吐量。如果任务频繁阻塞(例如,如果它们是I/O边界),则系统可能为超过您许可的更多线程安排时间。<br style="line-height:25px"> 使用小型队列通常要求较大的池大小,CPU使用率较高,但是可能遇到不可接受的调度开销,这样也会降低吞吐量。<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">被拒绝的任务</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"> 当Executor已经关闭,或Executor将有限边界用于最大线程和工作队列容量,且已经饱和时,<br style="line-height:25px"> 在方法execute(java.lang.Runnable)中提交的新任务将被拒绝。<br style="line-height:25px"> 在以上两种情况下,execute方法都将调用其<br style="line-height:25px"><span style="color:#99cc00; line-height:25px">RejectedExecutionHandler</span>的<span style="color:#0000ff; line-height:25px">RejectedExecutionHandler.rejectedExecution(java.lang.Runnable,java.util.concurrent.ThreadPoolExecutor)</span>方法。<br style="line-height:25px"> 下面提供了<wbr style="line-height:25px"><span style="color:#003366; line-height:25px">四种预定义的处理程序策略</span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#000080; line-height:25px">1.在默认的</span><span style="color:#ff9900; line-height:25px">ThreadPoolExecutor.AbortPolicy</span><span style="color:#000080; line-height:25px">中,处理程序遭到拒绝将抛出运行时RejectedExecutionException。<br style="line-height:25px"> 2.在</span><span style="color:#ff9900; line-height:25px">ThreadPoolExecutor.CallerRunsPolicy</span><span style="color:#000080; line-height:25px">中,线程调用运行该任务的execute本身。<br style="line-height:25px"> 此策略提供简单的反馈控制机制,能够减缓新任务的提交速度。<br style="line-height:25px"> 3.在</span><span style="color:#ff9900; line-height:25px">ThreadPoolExecutor.DiscardPolicy</span><span style="color:#000080; line-height:25px">中,不能执行的任务将被删除。<br style="line-height:25px"> 4.在</span><span style="color:#ff9900; line-height:25px">ThreadPoolExecutor.DiscardOldestPolicy</span><span style="color:#000080; line-height:25px">中,如果执行程序尚未关闭,<br style="line-height:25px"> 则位于工作队列头部的任务将被删除,然后重试执行程序(如果再次失败,则重复此过程)。</span><br style="line-height:25px"> 定义和使用其他种类的RejectedExecutionHandler类也是可能的,但这样做需要非常小心,尤其是当策略仅用于特定容量或排队策略时<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:AbortPolicy,CallerRunsPolicy,DiscardPolicy和DiscardOldestPolicy都是rejectedExecution的一种实现。<br style="line-height:25px"> 当然也可以自己定义个rejectedExecution实现。<br style="line-height:25px"><span style="color:#993300; line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">钩子</wbr></span><wbr style="line-height:25px">(hook)方法</wbr></span><br style="line-height:25px"> 此类提供protected可重写的<span style="color:#0000ff; line-height:25px"></span><span style="color:#339966; line-height:25px">beforeExecute(</span>java.lang.Thread,java.lang.Runnable)<br style="line-height:25px"> 和<span style="color:#808000; line-height:25px">afterExecute</span>(java.lang.Runnable,java.lang.Throwable)方法,这两种方法分别在执行每个任务之前和之后调用。<br style="line-height:25px"> 它们可用于操纵执行环境;例如,重新初始化ThreadLocal、搜集统计信息或添加日志条目。<br style="line-height:25px"> 此外,还可以重写方法<span style="color:#99cc00; line-height:25px">terminated()</span>来执行Executor完全终止后需要完成的所有特殊处理。<br style="line-height:25px"><span style="color:#000080; line-height:25px"><wbr style="line-height:25px">如果钩子(hook)或回调方法抛出异常,则ThreadPoolExecutor的所有线程将依次失败并突然终止<wbr style="line-height:25px">。<br style="line-height:25px"><wbr style="line-height:25px">队列维护</wbr></wbr></wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#000080; line-height:25px">方法getQueue()允许出于监控和调试目的而访问工作队列。强烈反对出于其他任何目的而使用此方法。</span><br style="line-height:25px"><span style="color:#339966; line-height:25px">remove</span>(java.lang.Runnable)和<span style="color:#008000; line-height:25px">purge()</span>这两种方法可用于在取消大量已排队任务时帮助进行存储回收。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意</wbr></span><wbr style="line-height:25px">1:如果任务取消,ThreadPoolExecutor应该自己是可以进行存储回收的。<br style="line-height:25px"> 取消的任务不会再次执行,但是它们可能在工作队列中累积,直到worker线程主动将其移除<br style="line-height:25px"> 外部使用<span style="color:#339966; line-height:25px">remove</span>(java.lang.Runnable)和<span style="color:#008000; line-height:25px">purge()</span>可以把它们立即从队列中移除。<br style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px"><wbr style="line-height:25px">终止</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#003366; line-height:25px">如果ThreadPoolExecutor在程序中没有任何引用且没有任何活动线程,它也不会自动shutdown。<br style="line-height:25px"> 如果希望确保回收线程(即使用户忘记调用shutdown()),则必须安排未使用的线程最终终止:</span><br style="line-height:25px"><span style="color:#000080; line-height:25px">设置适当保持活动时间,使用0核心线程的下边界和/或设置allowCoreThreadTimeOut(boolean)。</span><br style="line-height:25px"> 扩展示例。此类的大多数扩展可以重写一个或多个受保护的钩子(hook)方法。例如,下面是一个添加了简单的暂停/恢复功能的子类:<br style="line-height:25px"><span style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"></span> <pre class="prettyprint" style="line-height:inherit; padding-top:10px; padding-right:10px; padding-bottom:10px; padding-left:10px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); color:rgb(0,112,0); font-family:monospace; background-color:rgb(250,250,250); margin-top:0px; margin-bottom:1em; margin-left:1em; overflow-x:auto; overflow-y:auto"><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"></span></span><code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">class</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">PausableThreadPoolExecutor</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">extends</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">ThreadPoolExecutor</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">private</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">boolean</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> isPaused</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">;</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">private</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">ReentrantLock</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">=</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">new</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">ReentrantLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">private</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Condition</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> unpaused </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">=</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">newCondition</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">public</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">PausableThreadPoolExecutor</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(...)</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">super</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(...);</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span></code><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">protected</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">void</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> beforeExecute</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Thread</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> t</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">,</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">Runnable</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> r</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">super</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">beforeExecute</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">t</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">,</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> r</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">);</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">lock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">try</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">while</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">isPaused</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> unpaused</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">await</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">catch</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">(</span></span><span style="line-height:23px; color:rgb(102,0,102)"><span class="typ" style="line-height:23px; color:rgb(102,0,102)">InterruptedException</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> ie</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">)</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> t</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">interrupt</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">finally</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">unlock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">public</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">void</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pause</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">()</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">lock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">try</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> isPaused </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">=</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">true</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">;</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">finally</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">unlock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">public</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">void</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> resume</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">()</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">lock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">try</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> isPaused </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">=</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">false</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">;</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> unpaused</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">signalAll</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(0,0,136)"><span class="kwd" style="line-height:23px; color:rgb(0,0,136)">finally</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">{</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> pauseLock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">.</span></span><span style="line-height:23px; color:rgb(0,0,0)"><span class="pln" style="line-height:23px; color:rgb(0,0,0)">unlock</span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">();</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"> </span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}</span></span><span style="line-height:23px; color:rgb(0,0,0)"><br style="line-height:23px"><span class="pln" style="line-height:23px; color:rgb(0,0,0)"></span></span><span style="line-height:23px; color:rgb(102,102,0)"><span class="pun" style="line-height:23px; color:rgb(102,102,0)">}}</span></span></pre> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr style="line-height:25px"></wbr>关于它的使用请参考《 ExecutorService
<wbr style="line-height:25px"><span style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"></span> <table id="nestedclasses" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:0.9em; border-collapse:collapse; empty-cells:show; width:933px"><tbody style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th colspan="12" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:rgb(222,232,241)"> Nested Classes</th> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; background-color:rgb(246,246,246)"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">class</nobr> </td> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.AbortPolicy.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">ThreadPoolExecutor.AbortPolicy</a> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> A handler for rejected tasks that throws a<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace">RejectedExecutionException</code>.</td> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">class</nobr> </td> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">ThreadPoolExecutor.CallerRunsPolicy</a> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> A handler for rejected tasks that runs the rejected task directly in the calling thread of the<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace">execute</code>method, unless the executor has been shut down, in which case the task is discarded.</td> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; background-color:rgb(246,246,246)"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">class</nobr> </td> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.DiscardOldestPolicy.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">ThreadPoolExecutor.DiscardOldestPolicy</a> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> A handler for rejected tasks that discards the oldest unhandled request and then retries<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace">execute</code>, unless the executor is shut down, in which case the task is discarded.</td> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">class</nobr> </td> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.DiscardPolicy.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">ThreadPoolExecutor.DiscardPolicy</a> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> A handler for rejected tasks that silently discards the rejected task.</td> </tr> </tbody></table> <span style="line-height:25px">主要构造函数</span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">public</span><span style="color:#ff00ff; line-height:25px"><wbr style="line-height:25px">ThreadPoolExecutor</wbr></span><wbr style="line-height:25px">(intcorePoolSize,<br style="line-height:25px"> intmaximumPoolSize,<br style="line-height:25px"> longkeepAliveTime,<br style="line-height:25px"> TimeUnitunit,<br style="line-height:25px"><span style="color:#ff9900; line-height:25px">BlockingQueue&lt;Runnable&gt;workQueue</span>)<br style="line-height:25px"><br style="line-height:25px"> 用给定的初始参数和默认的线程工厂及被拒绝的执行处理程序创建新的ThreadPoolExecutor。<br style="line-height:25px"> 使用Executors工厂方法之一比使用此通用构造方法方便得多。<br style="line-height:25px"> 参数:<br style="line-height:25px"> corePoolSize-池中所保存的线程数,包括空闲线程。<br style="line-height:25px"> maximumPoolSize-池中允许的最大线程数。<br style="line-height:25px"> keepAliveTime-当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间。<br style="line-height:25px"> unit-keepAliveTime参数的时间单位。<br style="line-height:25px"> workQueue-执行前用于保持任务的队列。此队列仅保持由execute方法提交的Runnable任务。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> IllegalArgumentException-如果corePoolSize或keepAliveTime小于0,或者maximumPoolSize小于等于0,<br style="line-height:25px"> 或者corePoolSize大于maximumPoolSize。<br style="line-height:25px"> NullPointerException-如果workQueue为null<br style="line-height:25px"><span style="color:#993300; line-height:25px">public</span><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">ThreadPoolExecutor</span><wbr style="line-height:25px">(intcorePoolSize,<br style="line-height:25px"> intmaximumPoolSize,<br style="line-height:25px"> longkeepAliveTime,<br style="line-height:25px"> TimeUnitunit,<br style="line-height:25px"><span style="color:#ff9900; line-height:25px">BlockingQueue&lt;Runnable&gt;workQueue,</span><br style="line-height:25px"> ThreadFactorythreadFactory)<br style="line-height:25px"><br style="line-height:25px"> 用给定的初始参数和默认被拒绝的执行处理程序创建新的ThreadPoolExecutor。<br style="line-height:25px"><br style="line-height:25px"> 参数:<br style="line-height:25px"> corePoolSize-池中所保存的线程数,包括空闲线程。<br style="line-height:25px"> maximumPoolSize-池中允许的最大线程数。<br style="line-height:25px"> keepAliveTime-当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间。<br style="line-height:25px"> unit-keepAliveTime参数的时间单位。<br style="line-height:25px"> workQueue-执行前用于保持任务的队列。此队列仅保持由execute方法提交的Runnable任务。<br style="line-height:25px"> threadFactory-执行程序创建新线程时使用的工厂。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> IllegalArgumentException-如果corePoolSize或keepAliveTime小于0,或者maximumPoolSize小于等于0,或者corePoolSize大于maximumPoolSize。<br style="line-height:25px"> NullPointerException-如果workQueue或threadFactory为null。<br style="line-height:25px"><span style="color:#993300; line-height:25px">public</span><span style="color:#ff00ff; line-height:25px"><wbr style="line-height:25px">ThreadPoolExecutor</wbr></span><wbr style="line-height:25px">(intcorePoolSize,<br style="line-height:25px"> intmaximumPoolSize,<br style="line-height:25px"> longkeepAliveTime,<br style="line-height:25px"> TimeUnitunit,<br style="line-height:25px"> BlockingQueue&lt;Runnable&gt;workQueue,<br style="line-height:25px"> RejectedExecutionHandlerhandler)<br style="line-height:25px"><br style="line-height:25px"> 用给定的初始参数和默认的线程工厂创建新的ThreadPoolExecutor。<br style="line-height:25px"><br style="line-height:25px"> 参数:<br style="line-height:25px"> corePoolSize-池中所保存的线程数,包括空闲线程。<br style="line-height:25px"> maximumPoolSize-池中允许的最大线程数。<br style="line-height:25px"> keepAliveTime-当线程数大于核心时,此为终止前多余的空闲线程等待新任务的最长时间。<br style="line-height:25px"> unit-keepAliveTime参数的时间单位。<br style="line-height:25px"> workQueue-执行前用于保持任务的队列。此队列仅由保持execute方法提交的Runnable任务。<br style="line-height:25px"> handler-由于超出线程范围和队列容量而使执行被阻塞时所使用的处理程序。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> IllegalArgumentException-如果corePoolSize或keepAliveTime小于0,或者maximumPoolSize小于等于0,<br style="line-height:25px"> 或者corePoolSize大于maximumPoolSize。</wbr></wbr></wbr></wbr></wbr></wbr>
主要成员函数
publicvoid <wbr style="line-height:25px">execute</wbr><wbr style="line-height:25px">(Runnablecommand)<br style="line-height:25px"> 在将来某个时间执行给定任务。可以在新线程中或者在现有池线程中执行该任务。如果无法将任务提交执行,或者因为此执行程序已关闭,或者因为已达到其容量,则该任务由当前RejectedExecutionHandler处理。<br style="line-height:25px"> 参数:<br style="line-height:25px"> command-要执行的任务。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> RejectedExecutionException-如果无法接收要执行的任务,则由RejectedExecutionHandler决定是否抛出RejectedExecutionException<br style="line-height:25px"> NullPointerException-如果命令为null<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicvoid</span><span style="color:#ff6600; line-height:25px"><wbr style="line-height:25px">shutdown<wbr style="line-height:25px">()</wbr></wbr></span><br style="line-height:25px"> 按过去执行已提交任务的顺序发起一个有序的关闭,但是不接受新任务。如果已经关闭,则调用没有其他作用。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> SecurityException-如果安全管理器存在并且关闭此ExecutorService可能操作某些不允许调用者修改的线程(因为它没有RuntimePermission("modifyThread")),或者安全管理器的checkAccess方法拒绝访问。<br style="line-height:25px"><span style="color:#993300; line-height:25px">public</span>List&lt;Runnable&gt;<span style="color:#ff6600; line-height:25px"><wbr style="line-height:25px">shutdownNow<wbr style="line-height:25px">()</wbr></wbr></span><br style="line-height:25px"> 尝试停止所有的活动执行任务、暂停等待任务的处理,并返回等待执行的任务列表。在从此方法返回的任务队列中排空(移除)这些任务。<br style="line-height:25px"> 并不保证能够停止正在处理的活动执行任务,但是会尽力尝试。此实现通过Thread.interrupt()取消任务,所以无法响应中断的任何任务可能永远无法终止。<br style="line-height:25px"> 返回:<br style="line-height:25px"> 从未开始执行的任务的列表。<br style="line-height:25px"> 抛出:<br style="line-height:25px"> SecurityException-如果安全管理器存在并且关闭此ExecutorService<br style="line-height:25px"> 可能操作某些不允许调用者修改的线程(因为它没有RuntimePermission("modifyThread")),<br style="line-height:25px"> 或者安全管理器的checkAccess方法拒绝访问。<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicint</span><span style="color:#ff6600; line-height:25px">prestartAllCoreThreads()</span><br style="line-height:25px"> 启动所有核心线程,使其处于等待工作的空闲状态。仅当执行新任务时,此操作才重写默认的启动核心线程策略。<br style="line-height:25px"> 返回:<br style="line-height:25px"> 已启动的线程数<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicboolean</span><wbr style="line-height:25px"><span style="color:#ff6600; line-height:25px">allowsCoreThreadTimeOut<wbr style="line-height:25px">()</wbr></span><br style="line-height:25px"> 如果此池允许核心线程超时和终止,如果在keepAlive时间内没有任务到达,新任务到达时正在替换(如果需要),则返回true。当返回true时,适用于非核心线程的相同的保持活动策略也同样适用于核心线程。当返回false(默认值)时,由于没有传入任务,核心线程不会终止。<br style="line-height:25px"> 返回:<br style="line-height:25px"> 如果允许核心线程超时,则返回true;否则返回false<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicvoid</span><span style="color:#ff6600; line-height:25px">allowCoreThreadTimeOut</span>(booleanvalue)<br style="line-height:25px"> 如果在保持活动时间内没有任务到达,新任务到达时正在替换(如果需要),则设置控制核心线程是超时还是终止的策略。当为false(默认值)时,由于没有传入任务,核心线程将永远不会中止。当为true时,适用于非核心线程的相同的保持活动策略也同样适用于核心线程。为了避免连续线程替换,保持活动时间在设置为true时必须大于0。通常应该在主动使用该池前调用此方法。<br style="line-height:25px"> 参数:<br style="line-height:25px"> value-如果应该超时,则为true;否则为false<br style="line-height:25px"> 抛出:<br style="line-height:25px"> IllegalArgumentException-如果value为true并且当前保持活动时间不大于0。<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicboolean</span><span style="color:#ff6600; line-height:25px"><span style="line-height:25px"></span><wbr style="line-height:25px">remove</wbr></span><wbr style="line-height:25px">(Runnabletask)<br style="line-height:25px"> 从执行程序的内部队列中移除此任务(如果存在),从而如果尚未开始,则让其不再运行。<br style="line-height:25px"> 此方法可用作取消方案的一部分。它可能无法移除在放置到内部队列之前已经转换为其他形式的任务。<br style="line-height:25px"> 例如,使用submit输入的任务可能被转换为维护Future状态的形式。但是,在此情况下,purge()方法可用于移除那些已被取消的Future。<br style="line-height:25px"> 参数:<br style="line-height:25px"> task-要移除的任务<br style="line-height:25px"> 返回:<br style="line-height:25px"> 如果已经移除任务,则返回true<br style="line-height:25px"><span style="color:#993300; line-height:25px">publicvoid</span><wbr style="line-height:25px"><span style="line-height:25px"></span><span style="color:#ff6600; line-height:25px">purge</span><span style="color:#ff6600; line-height:25px"><wbr style="line-height:25px">()</wbr></span><br style="line-height:25px"> 尝试从工作队列移除所有已取消的Future任务。此方法可用作存储回收操作,它对功能没有任何影响。<br style="line-height:25px"> 取消的任务不会再次执行,但是它们可能在工作队列中累积,直到worker线程主动将其移除。<br style="line-height:25px"> 调用此方法将<wbr style="line-height:25px"><span style="color:#000080; line-height:25px">试图立即移除它们</span><wbr style="line-height:25px">。但是,如果出现其他线程的干预,那么此方法移除任务将失败。 <div style="line-height:25px"> <span style="color:#003366; line-height:25px">当然它还实现了的</span><span style="line-height:25px; color:rgb(255,153,0)">ExecutorService</span><span style="color:#003366; line-height:25px">的</span><span style="color:#ff6600; line-height:25px">submit</span><span style="color:#003366; line-height:25px">系列接口</span> </div> <div style="line-height:25px"> <div style="line-height:25px"> <span style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"></span> <table id="pubmethods" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:0.9em; border-collapse:collapse; empty-cells:show; width:933px"><tbody style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">abstract &lt;T&gt;<a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/Future.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Future</a>&lt;T&gt;</nobr> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ExecutorService.html#submit(java.lang.Runnable,%20T)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">submit</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/java/lang/Runnable.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Runnable</a>task, T result)</nobr><div style="line-height:25px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:3px; padding-right:1em; padding-bottom:0px; padding-left:1em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-style:initial; border-color:initial"> Submits a Runnable task for execution and returns a Future representing that task.</div> <div style="line-height:25px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:3px; padding-right:1em; padding-bottom:0px; padding-left:1em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-style:initial; border-color:initial"> 如果执行成功就返回<span style="color:#0000ff; line-height:21px">T result</span> </div> </td> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; background-color:rgb(246,246,246)"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">abstract &lt;T&gt;<a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/Future.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Future</a>&lt;T&gt;</nobr> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ExecutorService.html#submit(java.util.concurrent.Callable&lt;T&gt;)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">submit</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/Callable.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Callable</a>&lt;T&gt; task)</nobr><div style="line-height:25px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:3px; padding-right:1em; padding-bottom:0px; padding-left:1em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-style:initial; border-color:initial"> Submits a value-returning task for execution and returns a Future representing the pending results of the task.</div> </td> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px">abstract<a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/Future.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Future</a>&lt;?&gt;</nobr> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/ExecutorService.html#submit(java.lang.Runnable)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">submit</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/java/lang/Runnable.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Runnable</a>task)</nobr><div style="line-height:25px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:3px; padding-right:1em; padding-bottom:0px; padding-left:1em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-style:initial; border-color:initial"> Submits a Runnable task for execution and returns a Future representing that task.</div> </td> </tr> </tbody></table> <div style="line-height:25px">关于的<span style="line-height:25px; color:rgb(255,153,0)">ExecutorService</span>更多内容请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920109544134947/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">ExecutorService</a></strong>》</div> <div style="line-height:25px"> <br style="line-height:25px"> </div> </div> </div> </wbr></wbr></wbr></wbr></wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值