Multithread the orc loading process.
This commit is contained in:
parent
0c9ac572d1
commit
8c34d8488a
@ -4,7 +4,6 @@ import java.io.PrintStream;
|
||||
import java.util.Locale;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import net.sf.openrocket.database.ComponentPresetDatabase;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.l10n.DebugTranslator;
|
||||
import net.sf.openrocket.l10n.L10N;
|
||||
@ -39,7 +38,6 @@ public class Startup {
|
||||
|
||||
private static final int LOG_BUFFER_LENGTH = 50;
|
||||
|
||||
|
||||
/**
|
||||
* OpenRocket startup main method.
|
||||
*/
|
||||
@ -56,18 +54,12 @@ public class Startup {
|
||||
// Setup the translations
|
||||
initializeL10n();
|
||||
|
||||
// Must be done after localization is initialized
|
||||
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase();
|
||||
componentPresetDao.load("datafiles/presets", "(?i).*orc");
|
||||
Application.setComponentPresetDao( componentPresetDao );
|
||||
|
||||
// Continue startup in Startup2 class (where Application is already set up)
|
||||
Startup2.runMain(args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set proper system properties if openrocket.debug is defined.
|
||||
*/
|
||||
|
@ -5,6 +5,11 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
@ -13,6 +18,7 @@ import javax.swing.ToolTipManager;
|
||||
|
||||
import net.sf.openrocket.communication.UpdateInfo;
|
||||
import net.sf.openrocket.communication.UpdateInfoRetriever;
|
||||
import net.sf.openrocket.database.ComponentPresetDatabase;
|
||||
import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.database.ThrustCurveMotorSet;
|
||||
import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
|
||||
@ -90,6 +96,25 @@ public class Startup2 {
|
||||
log.info("Initializing the splash screen");
|
||||
Splash.init();
|
||||
|
||||
// Latch which counts the number of background loading processes we need to complete.
|
||||
CountDownLatch loading = new CountDownLatch(1);
|
||||
ExecutorService exec = Executors.newFixedThreadPool(2, new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setPriority(Thread.MIN_PRIORITY);
|
||||
return t;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Must be done after localization is initialized
|
||||
ComponentPresetDatabase componentPresetDao = new ComponentPresetDatabase();
|
||||
exec.submit( new ComponentPresetLoader( loading, componentPresetDao));
|
||||
|
||||
Application.setComponentPresetDao( componentPresetDao );
|
||||
|
||||
// Setup the uncaught exception handler
|
||||
log.info("Registering exception handler");
|
||||
SwingExceptionHandler exceptionHandler = new SwingExceptionHandler();
|
||||
@ -122,6 +147,12 @@ public class Startup2 {
|
||||
loadMotor();
|
||||
Databases.fakeMethod();
|
||||
|
||||
try {
|
||||
loading.await();
|
||||
} catch ( InterruptedException iex) {
|
||||
|
||||
}
|
||||
|
||||
// Starting action (load files or open new document)
|
||||
log.info("Opening main application window");
|
||||
if (!handleCommandLine(args)) {
|
||||
@ -270,6 +301,25 @@ public class Startup2 {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
private static class ComponentPresetLoader implements Callable {
|
||||
|
||||
CountDownLatch latch;
|
||||
ComponentPresetDatabase componentPresetDao;
|
||||
|
||||
private ComponentPresetLoader( CountDownLatch latch, ComponentPresetDatabase componentPresetDao ) {
|
||||
this.componentPresetDao = componentPresetDao;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
componentPresetDao.load("datafiles/presets", "(?i).*orc");
|
||||
latch.countDown();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles arguments passed from the command line. This may be used either
|
||||
* when starting the first instance of OpenRocket or later when OpenRocket is
|
||||
|
Loading…
x
Reference in New Issue
Block a user