diff --git a/src/main/java/ini/trakem2/display/Display3D.java b/src/main/java/ini/trakem2/display/Display3D.java index 4769550e..189bfc31 100644 --- a/src/main/java/ini/trakem2/display/Display3D.java +++ b/src/main/java/ini/trakem2/display/Display3D.java @@ -450,28 +450,26 @@ public Vector> call() { setWaitingCursor(); - // Start new scheduler to publish/add meshes to the 3D Viewer every 5 seconds and when done. + // Start new scheduler to publish/add meshes to the 3D Viewer every 4 seconds and when done. final Hashtable> contents = new Hashtable>(); final ScheduledExecutorService updater = Executors.newScheduledThreadPool(1); final AtomicInteger counter = new AtomicInteger(); - updater.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - // Obtain a copy of the contents queue - final HashMap> m = new HashMap>(); - synchronized (contents) { - m.putAll(contents); - contents.clear(); - } - if (m.isEmpty()) return; - // Add all to the corresponding Display3D - for (final Map.Entry> e : m.entrySet()) { - e.getKey().universe.addContentLater(e.getValue()); - counter.getAndAdd(e.getValue().size()); - } - Utils.showStatus(new StringBuilder("Rendered ").append(counter.get()).append('/').append(hs.size()).toString()); + Runnable updaterTask = () -> { + // Obtain a copy of the contents queue + final HashMap> m = new HashMap>(); + synchronized (contents) { + m.putAll(contents); + contents.clear(); } - }, 100, 4000, TimeUnit.MILLISECONDS); + if (m.isEmpty()) return; + // Add all to the corresponding Display3D + for (final Map.Entry> e : m.entrySet()) { + e.getKey().universe.addContentLater(e.getValue()); + counter.getAndAdd(e.getValue().size()); + } + Utils.showStatus(new StringBuilder("Rendered ").append(counter.get()).append('/').append(hs.size()).toString()); + }; + updater.scheduleWithFixedDelay(updaterTask, 100, 4000, TimeUnit.MILLISECONDS); // A list of all generated Content objects final Vector> list = new Vector>(); @@ -556,14 +554,10 @@ public void run() { IJError.print(t); } } - try { - // Shutdown scheduler and execute remaining tasks - for (final Runnable r : updater.shutdownNow()) { - r.run(); - } - } catch (final Throwable e) { - IJError.print(e); - } + // Shutdown scheduler + updater.shutdown(); + // …and run once more in case we were in a delay between calls + updaterTask.run(); // Reset cursor doneWaiting(); Utils.showStatus(new StringBuilder("Done rendering ").append(counter.get()).append('/').append(hs.size()).toString());