Java: Force stopping of ExecutorService threads

后端 未结 6 714
天涯浪人
天涯浪人 2020-12-17 00:44

My code:


String[] torrentFiles = new File(\"/root/torrents/\").list();

        if(torrentFiles.length == 0 || torrentFiles == null)
        {
            S         


        
6条回答
  •  情深已故
    2020-12-17 01:32

    ExecutorService.shutdownNow() will try to stop all the executing threads..

    Here is a quote from javadoc

    List shutdownNow()

    Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

    There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so if any tasks mask or fail to respond to interrupts, they may never terminate.

提交回复
热议问题