]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/internal/Threads.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / internal / Threads.java
index be25de632b990e81742424f6211ec2f4e884b57c..9e2a4384bcaa4eebf677db4aff9a8d6f3e2f5314 100644 (file)
@@ -1,95 +1,95 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt.internal;\r
-\r
-import java.util.concurrent.ExecutorService;\r
-import java.util.concurrent.Executors;\r
-import java.util.concurrent.LinkedBlockingQueue;\r
-import java.util.concurrent.ThreadFactory;\r
-import java.util.concurrent.ThreadPoolExecutor;\r
-import java.util.concurrent.TimeUnit;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
-\r
-import org.simantics.browsing.ui.swt.Activator;\r
-\r
-/**\r
- * Pooled thread work executor for GraphExplorerImpl internal use only.\r
- * \r
- * Started by {@link Activator}.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public final class Threads {\r
-\r
-    private static ExecutorService     executor;\r
-\r
-    public static synchronized void initialize() {\r
-        if (executor == null) {\r
-            initializeExecutor();\r
-        }\r
-    }\r
-\r
-    public static synchronized void shutdown() {\r
-        if (executor != null) {\r
-            executor.shutdown();\r
-            executor = null;\r
-        }\r
-    }\r
-\r
-    private static ExecutorService initializeExecutor() {\r
-        if (executor == null) {\r
-            final ThreadGroup tg = new ThreadGroup("GraphExplorer-Worker-Group");\r
-            final AtomicInteger counter = new AtomicInteger(0);\r
-            ThreadFactory tf = new ThreadFactory() {\r
-                @Override\r
-                public Thread newThread(Runnable r) {\r
-                    Thread t = new Thread(tg, r, "GraphExplorer-Worker-"+(counter.incrementAndGet()));\r
-                    if (!t.isDaemon())\r
-                        t.setDaemon(true);\r
-                    if (t.getPriority() != Thread.NORM_PRIORITY)\r
-                        t.setPriority(Thread.NORM_PRIORITY);\r
-                    return t;\r
-                }\r
-            };\r
-\r
-//            int maxPoolSize = Math.min(Math.max(2, ThreadUtils.CORES), 8);\r
-            int maxPoolSize = 1;\r
-            \r
-            if(maxPoolSize == 1) {\r
-               \r
-               executor = Executors.newSingleThreadExecutor(tf);\r
-               \r
-            } else {\r
-\r
-               executor =\r
-                       new ThreadPoolExecutor(maxPoolSize / 2, maxPoolSize,\r
-                                       // Don't let the threads die too soon\r
-                                       30L, TimeUnit.SECONDS,\r
-                                       // LinkedBlockingQueue to allow queueing of tasks\r
-                                       // even when all workers are busy.\r
-                                       new LinkedBlockingQueue<Runnable>(),\r
-                                       tf);\r
-            \r
-            }\r
-            \r
-        }\r
-        return executor;\r
-    }\r
-\r
-    public static ExecutorService getExecutor() {\r
-        ExecutorService service = executor;\r
-        if (service == null)\r
-            throw new IllegalStateException("executor not initialized");\r
-        return service;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.swt.internal;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.simantics.browsing.ui.swt.Activator;
+
+/**
+ * Pooled thread work executor for GraphExplorerImpl internal use only.
+ * 
+ * Started by {@link Activator}.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public final class Threads {
+
+    private static ExecutorService     executor;
+
+    public static synchronized void initialize() {
+        if (executor == null) {
+            initializeExecutor();
+        }
+    }
+
+    public static synchronized void shutdown() {
+        if (executor != null) {
+            executor.shutdown();
+            executor = null;
+        }
+    }
+
+    private static ExecutorService initializeExecutor() {
+        if (executor == null) {
+            final ThreadGroup tg = new ThreadGroup("GraphExplorer-Worker-Group");
+            final AtomicInteger counter = new AtomicInteger(0);
+            ThreadFactory tf = new ThreadFactory() {
+                @Override
+                public Thread newThread(Runnable r) {
+                    Thread t = new Thread(tg, r, "GraphExplorer-Worker-"+(counter.incrementAndGet()));
+                    if (!t.isDaemon())
+                        t.setDaemon(true);
+                    if (t.getPriority() != Thread.NORM_PRIORITY)
+                        t.setPriority(Thread.NORM_PRIORITY);
+                    return t;
+                }
+            };
+
+//            int maxPoolSize = Math.min(Math.max(2, ThreadUtils.CORES), 8);
+            int maxPoolSize = 1;
+            
+            if(maxPoolSize == 1) {
+               
+               executor = Executors.newSingleThreadExecutor(tf);
+               
+            } else {
+
+               executor =
+                       new ThreadPoolExecutor(maxPoolSize / 2, maxPoolSize,
+                                       // Don't let the threads die too soon
+                                       30L, TimeUnit.SECONDS,
+                                       // LinkedBlockingQueue to allow queueing of tasks
+                                       // even when all workers are busy.
+                                       new LinkedBlockingQueue<Runnable>(),
+                                       tf);
+            
+            }
+            
+        }
+        return executor;
+    }
+
+    public static ExecutorService getExecutor() {
+        ExecutorService service = executor;
+        if (service == null)
+            throw new IllegalStateException("executor not initialized");
+        return service;
+    }
+
+}