Java: Force stopping of ExecutorService threads

后端 未结 6 702
天涯浪人
天涯浪人 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:14

    Now I have to stop threads from a pool. I am doing it such a way. It may be not a good idea. Comment, please, if so.

    boolean isTerminated = mPoolThreads.isTerminated();
    while (!isTerminated) {
        mPoolThreads.shutdownNow();
        isTerminated = mPoolThreads.isTerminated();
        Log.i(Constants.LOG_TAG, "Stop threads: the threads are not terminated yet");
    }
    Log.w(Constants.LOG_TAG, "Stop threads: Terminated");
    

提交回复
热议问题