/hg/icedtea6: Set context classloader for all threads in an appl...
dbhole at icedtea.classpath.org
dbhole at icedtea.classpath.org
Fri May 7 13:41:20 PDT 2010
changeset 7cdfd5cb14cf in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=7cdfd5cb14cf
author: Deepak Bhole <dbhole at redhat.com>
date: Fri May 07 16:41:14 2010 -0400
Set context classloader for all threads in an applet's threadgroup
diffstat:
2 files changed, 20 insertions(+), 17 deletions(-)
ChangeLog | 9 +++++++++
netx/net/sourceforge/jnlp/Launcher.java | 28 +++++++++++-----------------
diffs (77 lines):
diff -r aab184d452dc -r 7cdfd5cb14cf ChangeLog
--- a/ChangeLog Fri May 07 12:02:50 2010 +0100
+++ b/ChangeLog Fri May 07 16:41:14 2010 -0400
@@ -1,3 +1,12 @@ 2010-05-07 Gary Benson <gbenson at redhat
+2010-05-07 Deepak Bhole <dbhole at redhat.com>
+
+ * netx/net/sourceforge/jnlp/Launcher.java
+ (setContextClassLoaderForAllThreads): Change to set context CL only for
+ given threadgroup.
+ (launchApplication): Supply threadgroup to
+ setContextClassLoaderForAllThreads.
+ (createApplet): Same.
+
2010-05-07 Gary Benson <gbenson at redhat.com>
* netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java:
diff -r aab184d452dc -r 7cdfd5cb14cf netx/net/sourceforge/jnlp/Launcher.java
--- a/netx/net/sourceforge/jnlp/Launcher.java Fri May 07 12:02:50 2010 +0100
+++ b/netx/net/sourceforge/jnlp/Launcher.java Fri May 07 16:41:14 2010 -0400
@@ -442,7 +442,7 @@ public class Launcher {
Method main = mainClass.getDeclaredMethod("main", new Class[] {String[].class} );
String args[] = file.getApplication().getArguments();
- setContextClassLoaderForAllThreads(app.getClassLoader());
+ setContextClassLoaderForAllThreads(app.getThreadGroup(), app.getClassLoader());
if (splashScreen != null) {
if (splashScreen.isSplashScreenValid()) {
@@ -464,30 +464,24 @@ public class Launcher {
}
/**
- * Set the classloader as the context classloader for all threads. This is
- * required to make some applications work. For example, an application that
- * provides a custom Swing LnF may ask the swing thread to load resources
- * from their JNLP, which would only work if the Swing thread knows about
- * the JNLPClassLoader.
+ * Set the classloader as the context classloader for all threads in
+ * the given threadgroup. This is required to make some applications
+ * work. For example, an application that provides a custom Swing LnF
+ * may ask the swing thread to load resources from their JNLP, which
+ * would only work if the Swing thread knows about the JNLPClassLoader.
*
+ * @param tg The threadgroup for which the context classloader should be set
* @param classLoader the classloader to set as the context classloader
*/
- private void setContextClassLoaderForAllThreads(ClassLoader classLoader) {
- ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
- ThreadGroup root;
-
- root = Thread.currentThread().getThreadGroup();
- while (root.getParent() != null) {
- root = root.getParent();
- }
+ private void setContextClassLoaderForAllThreads(ThreadGroup tg, ClassLoader classLoader) {
/* be prepared for change in thread size */
- int threadCountGuess = threadBean.getThreadCount();
+ int threadCountGuess = tg.activeCount();
Thread[] threads;
do {
threadCountGuess = threadCountGuess * 2;
threads = new Thread[threadCountGuess];
- root.enumerate(threads, true);
+ tg.enumerate(threads, true);
} while (threads[threadCountGuess-1] != null);
@@ -595,7 +589,7 @@ public class Launcher {
group.setApplication(appletInstance);
loader.setApplication(appletInstance);
- setContextClassLoaderForAllThreads(appletInstance.getClassLoader());
+ setContextClassLoaderForAllThreads(appletInstance.getThreadGroup(), appletInstance.getClassLoader());
return appletInstance;
}
More information about the distro-pkg-dev
mailing list