[icedtea-web] RFC: Patch to use wait() when waiting for conditions to become true

Omair Majid omajid at redhat.com
Thu Apr 14 12:00:11 PDT 2011


On 04/14/2011 02:29 PM, Deepak Bhole wrote:
> * Deepak Bhole<dbhole at redhat.com>  [2011-04-14 11:05]:
>> >  * Omair Majid<omajid at redhat.com>  [2011-04-14 10:56]:
>>> >  >  On 04/14/2011 01:56 AM, Deepak Bhole wrote:
> <snip>
>> >
>> >  Ah, neat. I didn't know that. I will make the change.
>> >
> New patch attached. It uses nanoTime().
>

Just one concern, noted below.

> @@ -142,14 +140,19 @@
>           initEventQueue(panel);
>
>           // Wait for panel to come alive
> -        int maxWait = PluginAppletViewer.APPLET_TIMEOUT; // wait for panel to come alive
> -        int wait = 0;
> -        while (!panel.isAlive()&&  wait<  maxWait) {
> -            try {
> -                Thread.sleep(50);
> -                wait += 50;
> -            } catch (InterruptedException ie) {
> -                // just wait
> +        // Wait implemented the long way so that
> +        // PluginAppletViewer.waitTillTimeout() needn't be exposed.
> +        long maxTimeToSleep = PluginAppletViewer.APPLET_TIMEOUT;
> +
> +        synchronized(panel) {
> +            while (!panel.isAlive()&&  maxTimeToSleep>  0) {
> +                long sleepStart = System.nanoTime();
> +
> +                try {
> +                    panel.wait(maxTimeToSleep);
> +                } catch (InterruptedException e) {} // Just loop back
> +
> +                maxTimeToSleep -= System.nanoTime() - sleepStart;

maxTimeToSleep is in ns, but wait expects ms. waitTillTimeout() converts 
the timeout in ns to ms before passing it to wait(). I think we should 
do something similar here.

Everything else looks fine to me.

Cheers,
Omair



More information about the distro-pkg-dev mailing list