[Schmitzm-commits] r1896 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 12 00:35:18 CET 2012


Author: alfonx
Date: 2012-03-12 00:35:17 +0100 (Mon, 12 Mar 2012)
New Revision: 1896

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
	/**
	 * Rauskopiert aus  ExecutorService JavaDoc
	 */
	void shutdownAndAwaitTermination(ExecutorService pool) {

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2012-03-11 13:55:44 UTC (rev 1895)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2012-03-11 23:35:17 UTC (rev 1896)
@@ -56,6 +56,7 @@
 import java.util.TimeZone;
 import java.util.TreeSet;
 import java.util.Vector;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -2291,4 +2292,24 @@
 		return splittedList;
 	}
 
+	/**
+	 * Rauskopiert aus  ExecutorService JavaDoc
+	 */
+	void shutdownAndAwaitTermination(ExecutorService pool) {
+		pool.shutdown(); // Disable new tasks from being submitted
+		try {
+			// Wait a while for existing tasks to terminate
+			if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
+				pool.shutdownNow(); // Cancel currently executing tasks
+				// Wait a while for tasks to respond to being cancelled
+				if (!pool.awaitTermination(60, TimeUnit.SECONDS))
+					System.err.println("Pool "+pool+" did not terminate");
+			}
+		} catch (InterruptedException ie) {
+			// (Re-)Cancel if current thread also interrupted
+			pool.shutdownNow();
+			// Preserve interrupt status
+			Thread.currentThread().interrupt();
+		}
+	}
 }



More information about the Schmitzm-commits mailing list