Ignore:
Timestamp:
2017-08-24T15:54:00+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate Main.worker, replace it by gui.MainApplication.worker + code refactoring to make sure only editor packages use it

File:
1 edited

Legend:

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

    r12633 r12634  
    77import java.awt.BorderLayout;
    88import java.awt.Dimension;
     9import java.awt.GraphicsEnvironment;
    910import java.awt.event.KeyEvent;
    1011import java.io.File;
     
    3637import java.util.TreeSet;
    3738import java.util.concurrent.Callable;
     39import java.util.concurrent.ExecutorService;
    3840import java.util.concurrent.Future;
    3941import java.util.logging.Level;
     
    5961import org.openstreetmap.josm.actions.mapmode.DrawAction;
    6062import org.openstreetmap.josm.actions.search.SearchAction;
    61 import org.openstreetmap.josm.data.AutosaveTask;
    6263import org.openstreetmap.josm.data.Bounds;
    63 import org.openstreetmap.josm.data.CustomConfigurator;
    6464import org.openstreetmap.josm.data.Version;
    6565import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6868import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
    6969import org.openstreetmap.josm.gui.download.DownloadDialog;
     70import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor;
     71import org.openstreetmap.josm.gui.layer.AutosaveTask;
    7072import org.openstreetmap.josm.gui.layer.TMSLayer;
    7173import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
     
    7375import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    7476import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
     77import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor;
    7578import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    7679import org.openstreetmap.josm.gui.util.GuiHelper;
     
    124127
    125128    /**
     129     * The worker thread slave. This is for executing all long and intensive
     130     * calculations. The executed runnables are guaranteed to be executed separately and sequential.
     131     * @since 12634 (as a replacement to {@code Main.worker})
     132     */
     133    public static final ExecutorService worker = new ProgressMonitorExecutor("main-worker-%d", Thread.NORM_PRIORITY);
     134
     135    /**
    126136     * Constructs a new {@code MainApplication} without a window.
    127137     */
     
    227237    @Override
    228238    protected void shutdown() {
     239        if (!GraphicsEnvironment.isHeadless()) {
     240            worker.shutdown();
     241        }
    229242        if (mainFrame != null) {
    230243            mainFrame.storeState();
     
    234247        }
    235248        super.shutdown();
     249        if (!GraphicsEnvironment.isHeadless()) {
     250            worker.shutdownNow();
     251        }
    236252    }
    237253
     
    456472
    457473        if (args.hasOption(Option.LOAD_PREFERENCES)) {
    458             CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
     474            XMLCommandProcessor config = new XMLCommandProcessor(Main.pref);
    459475            for (String i : args.get(Option.LOAD_PREFERENCES)) {
    460476                Logging.info("Reading preferences from " + i);
     
    671687        Future<?> future = task.download(true, b, null);
    672688        // ... and the continuation when the download is finished (this will wait for the download to finish)
    673         return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future)));
     689        return Collections.singletonList(MainApplication.worker.submit(new PostDownloadHandler(task, future)));
    674690    }
    675691
     
    693709        final Collection<String> selectionArguments = args.get(Option.SELECTION);
    694710        if (!selectionArguments.isEmpty()) {
    695             tasks.add(Main.worker.submit(() -> {
     711            tasks.add(MainApplication.worker.submit(() -> {
    696712                for (String s : selectionArguments) {
    697713                    SearchAction.search(s, SearchAction.SearchMode.add);
Note: See TracChangeset for help on using the changeset viewer.