在异常时关闭ThreadPoolTask​​Executor

时间:2019-12-27 23:22:22

标签: java multithreading spring-boot threadpoolexecutor

我有一个Spring Boot应用程序。其中使用ThreadPoolTask​​Executor。对于可运行的任何异常,我想关闭TaskExecutor。

<table
    id="table"
    data-toggle="table"
    data-sort-name="sort_order"
    data-sort-order="desc"
    data-toolbar="#toolbar"
    data-buttons-class="primary"
    data-show-toggle="true"
    data-show-columns="true"
    class="table table-lg table-hover table-striped"
   >
    <thead class="dataTableHeadingRow">
      <tr>
        <th data-field="action" class="text-md-right">Action</th>
      </tr>
    </thead>
    <tbody>
<td class="text-md-right" style=""><a href="http://localhost/shop/Admin/index.php?A&Categories&cID=14"><img data-src="http://localhost/shop/images/Admin/icons/edit.gif" alt="Editer" title="Editer" class="lozad media-object img-fluid"></a>&nbsp;<a href="http://localhost/shop/Admin/index.php?A&Categories&cID=14"><img data-src="http://localhost/shop/images/Admin/icons/move.gif" alt="Déplacer" title="Déplacer" class="lozad media-object img-fluid"></a>&nbsp;<a href="http://localhost/shop/Admin/index.php?AA&Categories&cID=14"><img data-src="http://localhost/shop/images/Admin/icons/delete.gif" alt="Supprimer" title="Supprimer" class="lozad media-object img-fluid"></a>&nbsp;</td>
   </tbody>
</table>

有人可以提供任何解决方案吗?

1 个答案:

答案 0 :(得分:0)

javadoc-shutdown()

  

启动有序关闭,在该关闭中执行先前提交的任务,但不接受任何新任务。如果已关闭,则调用不会产生其他影响。

因此对正在运行的任务没有影响。 使用shutdownNow(),您可以获取列表并在此处查看:How to stop a thread created by implementing runnable interface?

此外,latch.countDown()永远不会被触发(在RuntimeException的情况下...),因此您应该处理Exception,并且等待语句的倒数永远不会足够。 / p>

正如Tomaz Fernandes所写,该场景背后的问题可能会有所帮助。

相关问题