/hg/icedtea-web: Marking threads in ResourceTracker's threadPool...
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Tue Feb 24 15:17:54 UTC 2015
changeset d52d1381012f in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=d52d1381012f
author: Jiri Vanek <jvanek at redhat.com>
date: Tue Feb 24 16:17:28 2015 +0100
Marking threads in ResourceTracker's threadPool as daemons, so the dont prevent shutdown.
netx/net/sourceforge/jnlp/cache/CachedDaemonThreadPoolProvider.java: new file, implementation of ExecutorService singleton, whose threads are daemons.
netx/net/sourceforge/jnlp/cache/ResourceTracker.java: (startDownloadThread) now calls CachedDaemonThreadPoolProvider
diffstat:
ChangeLog | 8 +
netx/net/sourceforge/jnlp/cache/CachedDaemonThreadPoolProvider.java | 86 ++++++++++
netx/net/sourceforge/jnlp/cache/ResourceTracker.java | 12 +-
3 files changed, 98 insertions(+), 8 deletions(-)
diffs (148 lines):
diff -r a1b50e850558 -r d52d1381012f ChangeLog
--- a/ChangeLog Wed Feb 18 18:47:18 2015 +0100
+++ b/ChangeLog Tue Feb 24 16:17:28 2015 +0100
@@ -1,3 +1,11 @@
+2015-02-24 Jiri Vanek <jvanek at redhat.com>
+
+ Marking threads in ResourceTracker's threadPool as daemons, so the dont prevent shutdown.
+ * netx/net/sourceforge/jnlp/cache/CachedDaemonThreadPoolProvider.java: new file,
+ implementation of ExecutorService singleton, whose threads are daemons.
+ * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: (startDownloadThread)
+ now calls CachedDaemonThreadPoolProvider
+
2015-02-18 Jiri Vanek <jvanek at redhat.com>
Added menuentry to PolicyEditor to allow quicky open default java.policy
diff -r a1b50e850558 -r d52d1381012f netx/net/sourceforge/jnlp/cache/CachedDaemonThreadPoolProvider.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/cache/CachedDaemonThreadPoolProvider.java Tue Feb 24 16:17:28 2015 +0100
@@ -0,0 +1,86 @@
+/*
+ Copyright (C) 2011 Red Hat, Inc
+
+ This file is part of IcedTea.
+
+ IcedTea is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ IcedTea is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+package net.sourceforge.jnlp.cache;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class CachedDaemonThreadPoolProvider {
+
+ /**
+ * 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 DaemonThreadFactory 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;
+
+ DaemonThreadFactory() {
+ 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;
+ }
+ }
+
+ public static final ExecutorService DAEMON_THREAD_POOL = Executors.newCachedThreadPool(new DaemonThreadFactory());
+
+}
diff -r a1b50e850558 -r d52d1381012f netx/net/sourceforge/jnlp/cache/ResourceTracker.java
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java Wed Feb 18 18:47:18 2015 +0100
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Feb 24 16:17:28 2015 +0100
@@ -32,8 +32,6 @@
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import net.sourceforge.jnlp.DownloadOptions;
import net.sourceforge.jnlp.Version;
@@ -101,12 +99,10 @@
return requestMethods;
}
}
-
- /** notified on initialization or download of a resource */
+
+ /** 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();
-
/** the resources known about by this resource tracker */
private final List<Resource> resources = new ArrayList<>();
@@ -510,7 +506,7 @@
* </p>
*/
protected void startDownloadThread(Resource resource) {
- threadPool.execute(new ResourceDownloader(resource, lock));
+ CachedDaemonThreadPoolProvider.DAEMON_THREAD_POOL.execute(new ResourceDownloader(resource, lock));
}
static Resource selectByFilter(Collection<Resource> source, Filter<Resource> filter) {
@@ -633,4 +629,4 @@
interface Filter<T> {
public boolean test(T t);
}
-}
+}
\ No newline at end of file
More information about the distro-pkg-dev
mailing list