[OpenMap Users] Location threading problem with DeclutterMatrix.getGraphics()?

From: Carsten Ø. Madsen <com_at_navicon.dk>
Date: Thu, 17 Jan 2008 16:17:37 +0100

Hello

I'm running an OM app with multiple location layers on a quad core box
and I get the following exception on a regular basis:

Exception in thread "Thread-64" java.lang.NullPointerException
    at com.bbn.openmap.layer.location.Location.generate(Location.java:572)
    ...
    at
com.bbn.openmap.layer.location.LocationLayer$LocationWorker.construct(LocationLayer.java:176)
    at com.bbn.openmap.util.SwingWorker$2.run(SwingWorker.java:116)
    at java.lang.Thread.run(Thread.java:619)

The Location.generate() code goes like this:

    public boolean generate(Projection proj) {
        if (label != null) {
            label.setY(origYLabelOffset);
            label.setX(origXLabelOffset);
        }

        java.awt.Graphics g = DeclutterMatrix.getGraphics();
        if (g != null && label != null) {
            g.setFont(label.getFont());
            // Now set the vertical offset to the original place based
            // off the height of the label, so that the location place
            // is halfway up the text. That way, it looks like a
            // label.
            int height = g.getFontMetrics().getAscent(); // line 571
            currentFontDescent = g.getFontMetrics().getDescent();
            ....


as LocationLayer uses a LocationWorker (thread) to run prepare and
DeclutterMatrix.getGraphics() returns a static Graphics I assume the
exception is caused by multiple threads simultaneously accessing the
single graphics instance returned by DeclutterMatrix.getGraphics. As the
location layers stop responding after the exception this rather problematic.

As far as I can tell this is a general problem when having multiple
LocationLayers running on a multi core box?

BR
Carsten


--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Jan 17 2008 - 10:20:10 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT