Changeset 14139 in josm for trunk/src/org/openstreetmap/josm/spi/lifecycle
- Timestamp:
- 2018-08-12T02:52:44+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/spi/lifecycle
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/spi/lifecycle/Lifecycle.java
r14131 r14139 2 2 package org.openstreetmap.josm.spi.lifecycle; 3 3 4 import java.util.List; 4 5 import java.util.Objects; 6 import java.util.concurrent.ExecutionException; 7 import java.util.concurrent.ExecutorService; 8 import java.util.concurrent.Executors; 9 import java.util.concurrent.Future; 10 11 import org.openstreetmap.josm.tools.Logging; 12 import org.openstreetmap.josm.tools.Utils; 13 import org.openstreetmap.josm.tools.bugreport.BugReport; 5 14 6 15 /** … … 31 40 initStatusListener = Objects.requireNonNull(listener); 32 41 } 42 43 /** 44 * Initializes the main object. A lot of global variables are initialized here. 45 * @param initSequence Initialization sequence 46 * @since 14139 47 */ 48 public static void initialize(InitializationSequence initSequence) { 49 // Initializes tasks that must be run before parallel tasks 50 runInitializationTasks(initSequence.beforeInitializationTasks()); 51 52 // Initializes tasks to be executed (in parallel) by a ExecutorService 53 try { 54 ExecutorService service = Executors.newFixedThreadPool( 55 Runtime.getRuntime().availableProcessors(), Utils.newThreadFactory("main-init-%d", Thread.NORM_PRIORITY)); 56 for (Future<Void> i : service.invokeAll(initSequence.parallelInitializationTasks())) { 57 i.get(); 58 } 59 // asynchronous initializations to be completed eventually 60 initSequence.asynchronousRunnableTasks().forEach(service::submit); 61 initSequence.asynchronousCallableTasks().forEach(service::submit); 62 try { 63 service.shutdown(); 64 } catch (SecurityException e) { 65 Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown executor service", e); 66 } 67 } catch (InterruptedException | ExecutionException ex) { 68 throw new RuntimeException(ex); 69 } 70 71 // Initializes tasks that must be run after parallel tasks 72 runInitializationTasks(initSequence.afterInitializationTasks()); 73 } 74 75 private static void runInitializationTasks(List<InitializationTask> tasks) { 76 for (InitializationTask task : tasks) { 77 try { 78 task.call(); 79 } catch (RuntimeException e) { 80 // Can happen if the current projection needs NTV2 grid which is not available 81 // In this case we want the user be able to change his projection 82 BugReport.intercept(e).warn(); 83 } 84 } 85 } 33 86 }
Note:
See TracChangeset
for help on using the changeset viewer.