Ignore:
Timestamp:
2015-09-21T21:50:16+02:00 (6 years ago)
Author:
simon04
Message:

see #11843 - Run plugin tasks in the same thread

Before, a separate thread had been spawned for which termination had being waited immediately afterwards.

File:
1 edited

Legend:

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

    r8773 r8776  
    3535import java.util.concurrent.Callable;
    3636import java.util.concurrent.ExecutionException;
    37 import java.util.concurrent.ExecutorService;
    38 import java.util.concurrent.Executors;
    39 import java.util.concurrent.Future;
    4037import java.util.concurrent.FutureTask;
    4138import java.util.jar.JarFile;
     
    815812        try {
    816813            ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor);
    817             ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-loader-%d", Thread.NORM_PRIORITY));
    818             Future<?> future = service.submit(task);
    819814            try {
    820                 future.get();
    821             } catch (ExecutionException e) {
     815                task.run();
     816            } catch (RuntimeException e) {
    822817                Main.error(e);
    823                 return null;
    824             } catch (InterruptedException e) {
    825                 Main.warn("InterruptedException in "+PluginHandler.class.getSimpleName()+" while loading locally available plugin information");
    826818                return null;
    827819            }
     
    972964        try {
    973965            monitor.beginTask("");
    974             ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-updater-%d", Thread.NORM_PRIORITY));
    975966
    976967            // try to download the plugin lists
     
    980971                    Main.pref.getOnlinePluginSites(), displayErrMsg
    981972            );
    982             Future<?> future = service.submit(task1);
     973            task1.run();
    983974            List<PluginInformation> allPlugins = null;
    984975
    985976            try {
    986                 future.get();
    987977                allPlugins = task1.getAvailablePlugins();
    988978                plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false));
     
    1003993                    }
    1004994                }
    1005             } catch (ExecutionException e) {
    1006                 Main.warn(tr("Failed to download plugin information list")+": ExecutionException");
     995            } catch (RuntimeException e) {
     996                Main.warn(tr("Failed to download plugin information list"));
    1007997                Main.error(e);
    1008                 // don't abort in case of error, continue with downloading plugins below
    1009             } catch (InterruptedException e) {
    1010                 Main.warn(tr("Failed to download plugin information list")+": InterruptedException");
    1011998                // don't abort in case of error, continue with downloading plugins below
    1012999            }
     
    10481035                );
    10491036
    1050                 future = service.submit(pluginDownloadTask);
    10511037                try {
    1052                     future.get();
    1053                 } catch (ExecutionException e) {
     1038                    pluginDownloadTask.run();
     1039                } catch (RuntimeException e) {
    10541040                    Main.error(e);
    1055                     alertFailedPluginUpdate(parent, pluginsToUpdate);
    1056                     return plugins;
    1057                 } catch (InterruptedException e) {
    1058                     Main.warn("InterruptedException in "+PluginHandler.class.getSimpleName()+" while updating plugins");
    10591041                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    10601042                    return plugins;
Note: See TracChangeset for help on using the changeset viewer.