[RFC][plugin]: Class loading problem.

Omair Majid omajid at redhat.com
Fri Apr 29 10:36:24 PDT 2011


On 04/28/2011 05:24 PM, Denis Lila wrote:
>>> >  >  The attached patch fixes that. I believe a good enough
>>> >  >  explanation of what's happening is in the comments (if I'm
>>> >  >  wrong, don't hesitate to ask).
>> >
>> >  Eh, I forgot the attachment again.
> Hi.
>
> Turns out, this patch is incomplete. Better one attached.
> It also fixes a problem in the pogo.com games where
> all keystrokes when chatting are ignored.
>

Overall, this patch looks fine to me. Some comments inline.



> @@ -39,14 +40,51 @@
>    *
>    * @author      Francis Kung<fkung at redhat.com>
>    */
> + at SuppressWarnings("serial")
>   public class NetxPanel extends AppletViewerPanel {

Is there a particular reason you are suppressing this warning?

> +        this.uKey = "codebase=" + codebaseAttr +
> +                    "cache_archive=" + cache_archiveAttr +
> +                    "java_archive=" + java_archiveAttr +
> +                    "archive=" +  archiveAttr;
> +        // TODO: perhaps add some randomization in the name here?
> +        uKeyToTG.putIfAbsent(this.uKey, new ThreadGroup(Launcher.mainGroup, this.documentURL.toString()));

The comment below about the constructor parameters for new 
{App,}ThreadGroup() should be moved here.

> @@ -156,9 +182,7 @@
>
>           // when this was being done (incorrectly) in Launcher, the call was
>           // new AppThreadGroup(mainGroup, file.getTitle());
> -        ThreadGroup tg = new AppThreadGroup(Launcher.mainGroup,
> -                this.documentURL.toString());
> -        handler = new Thread(tg, this);
> +        handler = new Thread(getFutureTG(), this);
>           handler.start();
>       }
>
> @@ -174,4 +198,19 @@
>       public boolean isAlive() {
>           return handler != null&&  handler.isAlive()&&  this.appletAlive;
>       }
> +
> +    public ThreadGroup getFutureTG() {
> +        return uKeyToTG.get(uKey);
> +    }
> +

I am not sure if the name getFutureTG is appropriate, espcially given 
the check currentThreadGroup = getFutureTG() in the next few lines. I 
think getThreadGroup() would be fine.

> +    public void createNewAppContext() {
> +        if (Thread.currentThread().getThreadGroup() != getFutureTG()) {
> +            throw new RuntimeException("createNewAppContext called from the wrong thread.");
> +        }
> +        // only create a new one if one hasn't already been created for the
> +        // applets with this unique key.
> +        if (null == appContextCreated.putIfAbsent(uKey, Boolean.TRUE)) {
> +            SunToolkit.createNewAppContext();
> +        }
> +    }
>   }

... snip ...

> @@ -136,13 +136,29 @@
>               }
>           });
>
> -        // create the frame.
> -        PluginAppletViewer.framePanel(identifier, handle, panel);
> +        // Framing the panel needs to happen in a thread whose thread group
> +        // is the same as the threadgroup of the applet thread. If this
> +        // isn't the case, the awt eventqueue thread's context classloader
> +        // won't be set to a JNLPClassLoader, and when an applet class needs
> +        // to be loaded from the awt eventqueue, it won't be found.
> +        Thread panelInit = new Thread(panel.getFutureTG(), new Runnable() {
> +            @Override public void run() {
> +                panel.createNewAppContext();
> +                // create the frame.
> +                PluginAppletViewer.framePanel(identifier, handle, panel);
> +                panel.init();
> +                // Start the applet
> +                initEventQueue(panel);
> +            }
> +        }, "NetXPanel initializer");
>
> -        panel.init();
> -
> -        // Start the applet
> -        initEventQueue(panel);
> +        panelInit.start();
> +        while(panelInit.isAlive()) {
> +            try {
> +                panelInit.join();
> +            } catch (InterruptedException e) {
> +            }
> +        }
>

This part looks fine to me, but I am not too familiar with the 
concurrency requirements and communication between threads that goes on 
in PluginAppletViewer.

Cheers,
Omair



More information about the distro-pkg-dev mailing list