dsmiley commented on code in PR #2431: URL: https://github.com/apache/solr/pull/2431#discussion_r1585179206
########## solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java: ########## @@ -143,6 +173,37 @@ static void awaitTermination(ExecutorService pool, long timeout, TimeUnit unit) } } + /** + * Await the termination of an {@link ExecutorService} until all threads are complete, or until we + * are interrupted, at which point the {@link ExecutorService} will be interrupted as well. + * + * @param pool the ExecutorService to wait on + */ + public static void awaitTerminationForever(ExecutorService pool) { + boolean shutdown = false; + while (!shutdown) { + try { + try { + // Wait a while for existing tasks to terminate + shutdown = pool.awaitTermination(60, TimeUnit.SECONDS); + } catch (InterruptedException ie) { + // Force cancel if current thread also interrupted + pool.shutdownNow(); + // Preserve interrupt status + Thread.currentThread().interrupt(); Review Comment: Arguably, if we've given up waiting for awaiting termination, then the interruption has done its job and we don't need to keep the flag. ########## solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java: ########## @@ -143,6 +173,37 @@ static void awaitTermination(ExecutorService pool, long timeout, TimeUnit unit) } } + /** + * Await the termination of an {@link ExecutorService} until all threads are complete, or until we + * are interrupted, at which point the {@link ExecutorService} will be interrupted as well. + * + * @param pool the ExecutorService to wait on + */ + public static void awaitTerminationForever(ExecutorService pool) { + boolean shutdown = false; + while (!shutdown) { + try { + try { + // Wait a while for existing tasks to terminate + shutdown = pool.awaitTermination(60, TimeUnit.SECONDS); + } catch (InterruptedException ie) { + // Force cancel if current thread also interrupted + pool.shutdownNow(); + // Preserve interrupt status + Thread.currentThread().interrupt(); + if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { Review Comment: Wouldn't this always fail if you "preserve interrupt status" the line before? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org