Wow!  Sounds like you've been avoiding sleep in more ways than one. :-)

Anyway, since you mention the processQueue method, I did have to add a try
catch block to it because I was running into some timing dependent array
index out of range errors.  Like most of these kinds of problems, this only
happens about once a year.

           Runnable runnable;
           try {              //LDB: prevent "Array index out of range: 0"
               runnable =(Runnable) queuedRunnables.remove(0);
           } catch (ArrayIndexOutOfBoundsException ex) {
               return;
           }
          setRunningThreads(getRunningThreads()+1);

regards,
Larry

On 5/22/07, Sascha L. Teichmann <[EMAIL PROTECTED]> wrote:

Hi Larry,

The ThreadQueue .. my beloved enemy.
Yes, Larry, I know that and code like this is already in the
Print/Layout plug-in.

To avoid the sleep() loop I also add a special Runnable at
the end of that queue that unlocks a monitor when its executed.

Actually there are two ThreadQueues. The default one with
public access and and a second one with private access.
DB and WMS requests go to this private queue so there is
no possibility to sync with this beast.
You can temper with the Layerables Blackboard to force
them be rendered with the default queue. This is a workaround
and does not work very well. Counting my grey hairs I swear
there where less of them before I started with the ThreadQueue stuff.

The Implementation of the ThreadQueue is a horror (sorry, Jon ;-)
Starting a fresh new Thread for each Runnable .. no pooling at all.

Copy out of the source:

    private void processQueue() {
        while (!queuedRunnables.isEmpty() &&
                (runningThreads < maxRunningThreads) && enabled) {
            setRunningThreads(getRunningThreads()+1);
            new Thread((Runnable) queuedRunnables.remove(0)).start();
            // I wonder if it would improve performance to put a little
            // delay here. This loop seems pretty tight. Then again, I
haven't
            // worked with this code in several months, so I might be
mistaken.
            // [Jon Aquino 2005-03-2]
        }
    }

This thight loop eats CPU time!

The default queue is actually a Thread serializer because max
parallel threads are limited to 1! To achieve this you don't need
a thread queue ... There is also a EventListener mechanism that
is broken some how.

BTW: I've a new ThreadQueue implementation here, but it need's
a bit more of testing.

- Sascha




Larry Becker schrieb:
> Hi Sascha,
>
>    I have run into the WMS Layer problem you referred to.  It is caused
> by the fact that WMSLayer renders on a separate Thread.  To wait for
> those layers to finish rendering, I wait for the Thread queue to be
> empty as in the following snippet:
>
>               renderingManager.renderAll();
>               ThreadQueue runningThreads =
renderingManager.getDefaultRendererThreadQueue();
>               while (runningThreads.getRunningThreads()>0)
>                       Thread.sleep(200);
>
> regards,
> Larry
>
> On 5/22/07, *Stefan Steiniger* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     Hei Sascha,
>
>     thanx a lot.
>     are you going to commit it the openjump cvs repository?
>     would be nice :o)
>
>     stefan
>
>     Sascha L. Teichmann schrieb:
>     > Hi together,
>     >
>     > I'm currently hunting down some timing bugs in the Print/Layout
>     plug-in.
>     > If WMS layers are used they are not always imported correctly into
>     > the layout sheet.
>     >
>     > On my trip down the rendering path I found out that WMS layers
>     > do not cache the resulting images of there requests.
>     >
>     > I've written a patch (see attachment) against WMSLayer [1] that
stores
>     > the result of the last request using a pair of java.net.URL and
>     > java.lang.ref.SoftReference (java.awt.Image).
>     > If the next WMS request URL equals the last one the stored
>     > image is used and so expensive traffic is avoid.
>     >
>     > This does not solve my timing problem but it improves it a bit.
>     > IMHO this little tweak improves WMS performance in general
>     > by removing redundant HTTP traffic.
>     >
>     > Kind regards,
>     >   Sascha
>     >
>     > [1] com.vividsolutions.jump.workbench.model.WMSLayer
>     >
>     >
>     >
>
------------------------------------------------------------------------
>
>     >
>     > Index: src/com/vividsolutions/jump/workbench/model/WMSLayer.java
>     >
===================================================================
>     > RCS file:
>
/cvsroot/jump-pilot/openjump/src/com/vividsolutions/jump/workbench/model/WMSLayer.java,v
>
>     > retrieving revision 1.2
>     > diff -u -w -r1.2 WMSLayer.java
>     > --- src/com/vividsolutions/jump/workbench/model/WMSLayer.java 24
>     Jun 2005 09:01:57 -0000      1.2
>     > +++ src/com/vividsolutions/jump/workbench/model/WMSLayer.java 22
>     May 2007 16:16:43 -0000
>     > @@ -51,6 +51,11 @@
>     >  import com.vividsolutions.wms.MapRequest;
>     >  import com.vividsolutions.wms.WMService;
>     >
>     > +import java.net.URL;
>     > +
>     > +import java.lang.ref.Reference;
>     > +import java.lang.ref.SoftReference;
>     > +
>     >  /**
>     >   * A Layerable that retrieves images from a Web Map Server.
>     >   */
>     > @@ -66,6 +71,10 @@
>     >       private WMService service;
>     >
>     >       private String wmsVersion = WMService.WMS_1_0_0;
>     > +
>     > +     protected Reference oldImage;
>     > +     protected URL       oldURL;
>     > +
>     >       /**
>     >        * Called by Java2XML
>     >        */
>     > @@ -121,7 +130,20 @@
>     >       }
>     >
>     >       public Image createImage(LayerViewPanel panel) throws
>     IOException {
>     > -             Image image = createRequest(panel).getImage();
>     > +
>     > +             MapRequest request = createRequest(panel);
>     > +             URL        newURL  = request.getURL();
>     > +
>     > +             Image image;
>     > +
>     > +             // look if last request equals new one.
>     > +             // if it does take the image from the cache.
>     > +             if (oldURL == null
>     > +             || !newURL.equals(oldURL)
>     > +             || oldImage == null
>     > +             || (image = (Image)oldImage.get()) == null
>     > +             ) {
>     > +                     image = request.getImage();
>     >               MediaTracker mt = new MediaTracker(new JButton());
>     >               mt.addImage(image, 0);
>     >
>     > @@ -130,6 +152,9 @@
>     >               } catch (InterruptedException e) {
>     >                       Assert.shouldNeverReachHere();
>     >               }
>     > +                     oldImage = new SoftReference(image);
>     > +                     oldURL   = newURL;
>     > +             }
>     >
>     >               return image;
>     >       }
>     >
>     >
>     >
>
------------------------------------------------------------------------
>     >
>     >
>
-------------------------------------------------------------------------
>
>     > This SF.net email is sponsored by DB2 Express
>     > Download DB2 Express C - the FREE version of DB2 express and take
>     > control of your XML. No limits. Just data. Click to get it now.
>     > http://sourceforge.net/powerbar/db2/
>     >
>     >
>     >
>
------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > Jump-pilot-devel mailing list
>     > Jump-pilot-devel@lists.sourceforge.net
>     <mailto:Jump-pilot-devel@lists.sourceforge.net>
>     > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>     <https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel>
>
>
-------------------------------------------------------------------------
>     This SF.net email is sponsored by DB2 Express
>     Download DB2 Express C - the FREE version of DB2 express and take
>     control of your XML. No limits. Just data. Click to get it now.
>     http://sourceforge.net/powerbar/db2/
>     _______________________________________________
>     Jump-pilot-devel mailing list
>     Jump-pilot-devel@lists.sourceforge.net
>     <mailto:Jump-pilot-devel@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
>
>
> --
> http://amusingprogrammer.blogspot.com/
>
>
> ------------------------------------------------------------------------
>
>
-------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel




--
http://amusingprogrammer.blogspot.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to