Changeset 10999 in josm


Ignore:
Timestamp:
2016-09-14T12:44:16+02:00 (8 years ago)
Author:
michael2402
Message:

Force resetState() to run in the EDT thread to prevent deadlocks. Fixes #13632

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java

    r10998 r10999  
    2121 * This manager handles a list of layers with the first layer being the front layer.
    2222 * <h1>Threading</h1>
     23 * Synchronization of the layer manager is done by synchronizing all read/write access. All changes are internally done in the EDT thread.
     24 *
    2325 * Methods of this manager may be called from any thread in any order.
    24  * Listeners are called while this layer manager is locked, so they should not block.
     26 * Listeners are called while this layer manager is locked, so they should not block on other threads.
    2527 *
    2628 * @author Michael Zangl
     
    3537         * Notifies this listener that a layer has been added.
    3638         * <p>
    37          * Listeners are called in the EDT thread.
     39         * Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
    3840         * @param e The new added layer event
    3941         */
     
    4547         * Listeners are called in the EDT thread after the layer was removed.
    4648         * Use {@link LayerRemoveEvent#scheduleRemoval(Collection)} to remove more layers.
     49         * You should not do blocking or long-running tasks in this method.
    4750         * @param e The layer to be removed (as event)
    4851         */
     
    5255         * Notifies this listener that the order of layers was changed.
    5356         * <p>
    54          * Listeners are called in the EDT thread and you can manipulate the layer manager in the current thread.
     57         * Listeners are called in the EDT thread.
     58         *  You should not do blocking or long-running tasks in this method.
    5559         * @param e The order change event.
    5660         */
     
    418422     * @since 10432
    419423     */
    420     public synchronized void resetState() {
    421         // some layer remove listeners remove other layers.
     424    public void resetState() {
     425        // we force this on to the EDT Thread to have a clean synchronization
     426        // The synchronization lock needs to be held by the EDT.
     427        GuiHelper.runInEDTAndWaitWithException(this::realResetState);
     428    }
     429
     430    protected synchronized void realResetState() {
     431        // The listeners trigger the removal of other layers
    422432        while (!getLayers().isEmpty()) {
    423433            removeLayer(getLayers().get(0));
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r10997 r10999  
    372372
    373373    @Override
    374     public synchronized void resetState() {
     374    protected synchronized void realResetState() {
    375375        // active and edit layer are unset automatically
    376         super.resetState();
     376        super.realResetState();
    377377
    378378        activeLayerChangeListeners.clear();
Note: See TracChangeset for help on using the changeset viewer.