Mercurial > hg > release > icedtea6-1.8
changeset 2036:f5dc22b0171b
Set context classloader for all threads in an applet's threadgroup
2010-05-07 Deepak Bhole <dbhole@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.
author | Deepak Bhole <dbhole@redhat.com> |
---|---|
date | Fri, 07 May 2010 16:41:14 -0400 |
parents | 00a1c76d0040 |
children | a59c9d0cda71 |
files | ChangeLog netx/net/sourceforge/jnlp/Launcher.java |
diffstat | 2 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 Deepak Bhole <dbhole@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@redhat.com> * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.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 @@ 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 @@ } /** - * 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 @@ group.setApplication(appletInstance); loader.setApplication(appletInstance); - setContextClassLoaderForAllThreads(appletInstance.getClassLoader()); + setContextClassLoaderForAllThreads(appletInstance.getThreadGroup(), appletInstance.getClassLoader()); return appletInstance; }