Changeset 13316 in josm for trunk/src/org


Ignore:
Timestamp:
2018-01-14T00:39:35+01:00 (7 years ago)
Author:
Don-vip
Message:

see #15767 - change Main.listeners to CopyOnWriteArrayList and skip synchronization in Main.fireProjectionChanged (idea by bastiK)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r13249 r13316  
    99import java.lang.ref.WeakReference;
    1010import java.net.URL;
    11 import java.util.ArrayList;
    1211import java.util.Collection;
    1312import java.util.Collections;
     
    2019import java.util.Set;
    2120import java.util.concurrent.Callable;
     21import java.util.concurrent.CopyOnWriteArrayList;
    2222import java.util.concurrent.ExecutionException;
    2323import java.util.concurrent.ExecutorService;
     
    410410     * created dataset as projection change listener.
    411411     */
    412     private static final List<WeakReference<ProjectionChangeListener>> listeners = new ArrayList<>();
     412    private static final List<WeakReference<ProjectionChangeListener>> listeners = new CopyOnWriteArrayList<>();
    413413
    414414    private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) {
    415415        if ((newValue == null ^ oldValue == null)
    416416                || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
    417             synchronized (Main.class) {
    418                 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
    419                 while (it.hasNext()) {
    420                     WeakReference<ProjectionChangeListener> wr = it.next();
    421                     ProjectionChangeListener listener = wr.get();
    422                     if (listener == null) {
    423                         it.remove();
    424                         continue;
    425                     }
    426                     listener.projectionChanged(oldValue, newValue);
     417            Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
     418            while (it.hasNext()) {
     419                WeakReference<ProjectionChangeListener> wr = it.next();
     420                ProjectionChangeListener listener = wr.get();
     421                if (listener == null) {
     422                    it.remove();
     423                    continue;
    427424                }
     425                listener.projectionChanged(oldValue, newValue);
    428426            }
    429427            if (newValue != null && oldBounds != null && main != null) {
Note: See TracChangeset for help on using the changeset viewer.