[rfc][icedtea-web] make threads in ResourceTracker's ExecutorService daemon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As described in http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2015-February/030792.html (long thread) javaws do not close. The reason is that the trheads in ExecutorService  are never shut down.

One solution is to make them daemn (attached)

I prefer  this solution above others described in the thread.

J.
diff -r a8baec8d9d21 netx/net/sourceforge/jnlp/cache/ResourceTracker.java
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Fri Feb 13 12:48:24 2015 +0100
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Tue Feb 17 12:24:41 2015 +0100
@@ -34,6 +34,8 @@
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import net.sourceforge.jnlp.DownloadOptions;
 import net.sourceforge.jnlp.Version;
@@ -101,11 +103,45 @@
             return requestMethods;
         }
     }
+    
+    /**
+     * This is copypasted default factory from java.util.concurrent.Executors.
+     * The only difference is, that it creates daemon threads.
+     * 
+     * Except creating new threads, the rest of class is complicated creation of name.
+     */
+    private static class DefaultThreadFactory implements ThreadFactory {
+        private static final AtomicInteger poolNumber = new AtomicInteger(1);
+        private final ThreadGroup group;
+        private final AtomicInteger threadNumber = new AtomicInteger(1);
+        private final String namePrefix;
+
+        DefaultThreadFactory() {
+            SecurityManager s = System.getSecurityManager();
+            group = (s != null) ? s.getThreadGroup() :
+                                  Thread.currentThread().getThreadGroup();
+            namePrefix = "itwpool-" +
+                          poolNumber.getAndIncrement() +
+                         "-itwthread-";
+        }
+
+        @Override
+        public Thread newThread(Runnable r) {
+            Thread t = new Thread(group, r,
+                                  namePrefix + threadNumber.getAndIncrement(),
+                                  0);
+            if (!t.isDaemon())
+                t.setDaemon(true);
+            if (t.getPriority() != Thread.NORM_PRIORITY)
+                t.setPriority(Thread.NORM_PRIORITY);
+            return t;
+        }
+    }
 
     /** notified on initialization or download of a resource */
     private static final Object lock = new Object(); // used to lock static structures
 
-    private static final ExecutorService threadPool = Executors.newCachedThreadPool();
+    private static final ExecutorService threadPool = Executors.newCachedThreadPool(new DefaultThreadFactory());
 
     /** the resources known about by this resource tracker */
     private final List<Resource> resources = new ArrayList<>();
--
packaging mailing list
packaging@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/packaging

[Index of Archives]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Forum]     [KDE Users]

  Powered by Linux