X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fmain%2FSimulationRunDialog.java;h=3b170d421aa41030473bd56e086b156a18a4f8cf;hb=4e760733b56f5a60ba9c34a58b54899df2931ac4;hp=f85b248f640367a37df394fe710cabeef884e2d9;hpb=b556e8099ffd11d12ceb599a251d7c127bc81dc4;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java b/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java index f85b248f..3b170d42 100644 --- a/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java +++ b/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java @@ -10,8 +10,11 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Iterator; 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 javax.swing.JButton; import javax.swing.JDialog; @@ -58,8 +61,28 @@ public class SimulationRunDialog extends JDialog { private static final double APOGEE_PROGRESS = 0.7; - private final static ExecutorService executor = Executors.newFixedThreadPool( - SwingPreferences.getMaxThreadCount()); + /** + * A single ThreadPoolExecutor that will be used for all simulations. + * This executor must not be shut down. + */ + private static final ThreadPoolExecutor executor; + static { + int n = SwingPreferences.getMaxThreadCount(); + executor = new ThreadPoolExecutor(n, n, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(), + new ThreadFactory() { + private ThreadFactory factory = Executors.defaultThreadFactory(); + + @Override + public Thread newThread(Runnable r) { + Thread t = factory.newThread(r); + t.setDaemon(true); + return t; + } + }); + } + private final JLabel simLabel, timeLabel, altLabel, velLabel; @@ -172,10 +195,10 @@ public class SimulationRunDialog extends JDialog { * the Cancel button on the dialog. */ public void cancelSimulations() { - executor.shutdownNow(); for (SimulationWorker w : simulationWorkers) { w.cancel(true); } + executor.purge(); }