import java.io.InputStream;
import java.util.List;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
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;
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
@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();
private BookKeeping() {
- writerThread = Executors.newSingleThreadExecutor( new ThreadFactory() {
+ writerThread = new ThreadPoolExecutor(1,1,200, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(),
+ new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r,"MotorWriterThread");
}
});
- loaderPool = new ThreadPoolExecutor(25,25, 2, TimeUnit.SECONDS,
+ loaderPool = new ThreadPoolExecutor(10,10, 2, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new ThreadFactory() {
int threadCount = 0;
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();