Re: [OpenMap Users] Thread questions

From: Don Dietrick <>
Date: Thu, 4 May 2006 09:44:41 -0400

Hi Sean,

On May 4, 2006, at 6:05 AM, Donohue Sean wrote:

> Hi,
> I need to receive position data from a server written in C++, which
> means I need to learn about threading in JavaL. I've created a
> layer derived from OMGraphicHandlerLayer. All layers are Swing
> components, right?

> Does that mean that if I create a thread to handle the socket I/O
> then I can use SwingWorker.invokeLater to call some public method
> on my layer class and pass in the new positions to be added to the
> layer? No locks needed, all the thread safety is handled for me?
No, it doesn't. SwingUtils.invokeLater() has nothing to do with
Swing Components - it just causes the Runnable to be invoked in the
AWT Event thread. In general, you don't want to do any work in this
thread, it will slow down the 'feel' of the application.

There no magic in Java regarding thread safety. You still have to
manage synchronization if you have more than one thread accessing

> What about the GUI shown by the getGUI method? If I use that to
> filter some of the points in the layer, that happens in the event
> dispatching thread, yes? Is that the same as the layer thread or
> do I need to use the same technique here too?
getGUI() is not required to be called on the event thread, it's more
of a configuration method that parent components can call to get the
interface for a layer. If you return any Components from that method
call, you have to set up the listeners to handle them - and those
listeners will be called in the event thread. Again, you should
avoid doing heavy computation in that thread. It's better to create
a Runnable class, and pass it to a new Thread object, then call start
() on the Thread object.

The benefit of having Layers as Components is that you can call
repaint() on them when they are ready to have their stuff updated on
the map. The component architecture will handle layer paint order.

On OMGraphicHandlerLayer subclasses, you can call doPrepare(), and
the prepare() method will be called in a separate thread. The
OMGraphicHandlerLayer class will handle the OMGraphicList returned
from the prepare() method and get it painted on the map by calling
repaint() on itself with that thread is complete, and setting the
list to be rendered in the layer's paint() method.

You might want to check out the com.bbn.openmap.graphicLoader
package. If you create a class that extends AbstractGraphicLoader,
you get a class with an internal Timer that spawns threads at
specified intervals to do work. GraphicLoaders are expected to
create OMGraphicLists to send asynchronously to some listener, which
is generally a
com.bbn.openmap.plugin.graphicLoader.GraphicLoaderPlugIn (embedded in
a PlugInLayer). The benefit of this component structure is that you
can add your GraphicLoader to the MapHandler (either programmatically
or via the openmap.components property in the
file), and the PlugIn/PlugInLayer will automatically be created for
you, and the connections established. You can check out the
AnimationTester for an example of this, adding it to the
openmap.components property.

Hope this helps,


[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu May 04 2006 - 09:47:13 EDT

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