From dfa39e09cf3ffa44cc1e764bfa72900bab96136d Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 23 Mar 2017 18:47:41 +0000 Subject: [PATCH] JAL-2314 Tweaks to stop thread sync issues --- src/jalview/gui/Desktop.java | 2 ++ src/jalview/ws/jws2/Jws2Discoverer.java | 27 +++++++++++++++++++++ test/jalview/ws/jabaws/RNAStructExportImport.java | 6 +++++ 3 files changed, 35 insertions(+) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7d0eb7f..32e5f64 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -2875,6 +2875,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements || (t2 != null && t2.isAlive()) || (t3 != null && t3.isAlive()) || (t0 != null && t0.isAlive()); + // could just as easily ask discoverer if it is still running instead of + // holding ref to thread } } } diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index adca0fa..12a08a0 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -172,6 +172,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { } } + aborted = false; Cache.log.debug("Old discovery thread has finished."); } running = true; @@ -765,6 +766,22 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return true; } + public boolean restart() + { + synchronized (this) + { + if (running) + { + aborted = true; + } + else + { + running = true; + } + return aborted; + } + } + /** * Start a fresh discovery thread and notify the given object when we're * finished. Any known existing threads will be killed before this one is @@ -775,6 +792,16 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ public Thread startDiscoverer(PropertyChangeListener changeSupport2) { + /* if (restart()) + { + return; + } + else + { + Thread thr = new Thread(this); + thr.start(); + } + */ if (isRunning()) { setAborted(true); diff --git a/test/jalview/ws/jabaws/RNAStructExportImport.java b/test/jalview/ws/jabaws/RNAStructExportImport.java index 6cd32c7..23c7751 100644 --- a/test/jalview/ws/jabaws/RNAStructExportImport.java +++ b/test/jalview/ws/jabaws/RNAStructExportImport.java @@ -89,6 +89,12 @@ public class RNAStructExportImport Cache.initLogger(); disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false); + while (disc.isRunning()) + { + // don't get services until discoverer has finished + Thread.sleep(100); + } + for (Jws2Instance svc : disc.getServices()) { -- 1.7.10.2