X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fstartup%2FConcurrentLoadingThrustCurveMotorSetDatabase.java;h=2eba9b426206018e08596b273a8f633f70b731b6;hb=e21b77118f72c9c82ef379b3d044f042371f6d04;hp=a546f739e55ff2c5ccec5b636676c4cabdc27635;hpb=2152a7c12224c1545a5ee4375f097cf67d78609f;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/startup/ConcurrentLoadingThrustCurveMotorSetDatabase.java b/core/src/net/sf/openrocket/startup/ConcurrentLoadingThrustCurveMotorSetDatabase.java index a546f739..2eba9b42 100644 --- a/core/src/net/sf/openrocket/startup/ConcurrentLoadingThrustCurveMotorSetDatabase.java +++ b/core/src/net/sf/openrocket/startup/ConcurrentLoadingThrustCurveMotorSetDatabase.java @@ -9,6 +9,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import net.sf.openrocket.database.ThrustCurveMotorSet; import net.sf.openrocket.database.ThrustCurveMotorSetDatabase; @@ -47,6 +48,9 @@ public class ConcurrentLoadingThrustCurveMotorSetDatabase extends ThrustCurveMot private static final LogHelper log = Application.getLogger(); private final String thrustCurveDirectory; + /** Block motor loading for this many milliseconds */ + // Block motor loading for 1.5 seconds to allow window painting to be faster + private static AtomicInteger blockLoading = new AtomicInteger(1500); public ConcurrentLoadingThrustCurveMotorSetDatabase(String thrustCurveDirectory) { // configure ThrustCurveMotorSetDatabase as true so we get our own thread in @@ -58,6 +62,18 @@ public class ConcurrentLoadingThrustCurveMotorSetDatabase extends ThrustCurveMot @Override protected void loadMotors() { + // Block loading until timeout occurs or database is taken into use + log.info("Blocking motor loading while starting up"); + /* + while (!inUse && blockLoading.addAndGet(-100) > 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + */ + log.info("Blocking ended, inUse=" + inUse + " blockLoading=" + blockLoading.get()); + BookKeeping keeper = new BookKeeping(); keeper.start(); @@ -133,7 +149,7 @@ public class ConcurrentLoadingThrustCurveMotorSetDatabase extends ThrustCurveMot } }); - loaderPool = new ThreadPoolExecutor(25,25, 2, TimeUnit.SECONDS, + loaderPool = new ThreadPoolExecutor(10,10, 2, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { int threadCount = 0; @@ -162,9 +178,9 @@ public class ConcurrentLoadingThrustCurveMotorSetDatabase extends ThrustCurveMot private void waitForFinish() throws InterruptedException { try { loaderPool.shutdown(); - loaderPool.awaitTermination(10, TimeUnit.SECONDS); + loaderPool.awaitTermination(90, TimeUnit.SECONDS); writerThread.shutdown(); - writerThread.awaitTermination(10, TimeUnit.SECONDS); + writerThread.awaitTermination(90, TimeUnit.SECONDS); } finally { iterator.close();