From 9dbf492494f3a054ae007fa7ce17ddd2d9884c40 Mon Sep 17 00:00:00 2001 From: jprocter Date: Sun, 19 Sep 2010 16:35:34 +0000 Subject: [PATCH] make sure only one sequence datasource initialization thread runs at any one time --- src/jalview/gui/SequenceFetcher.java | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 7b42a3d..c5a9235 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -57,7 +57,8 @@ public class SequenceFetcher extends JPanel implements Runnable private static jalview.ws.SequenceFetcher sfetch = null; private static String dasRegistry = null; - + private static boolean _initingFetcher=false; + private static Thread initingThread=null; /** * Blocking method that initialises and returns the shared instance of the * SequenceFetcher client @@ -69,9 +70,29 @@ public class SequenceFetcher extends JPanel implements Runnable public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton( final IProgressIndicator guiWindow) { + if (_initingFetcher && initingThread!=null && initingThread.isAlive()) + { + if (guiWindow != null) + { + guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise", + Thread.currentThread().hashCode()); + } + // initting happening on another thread - so wait around to see if it finishes. + while (_initingFetcher && initingThread!=null && initingThread.isAlive()) + { + try {Thread.sleep(10);} catch (Exception e){}; + } + if (guiWindow != null) + { + guiWindow.setProgressBar("Waiting for Sequence Database Fetchers to initialise", + Thread.currentThread().hashCode()); + } + } if (sfetch == null || dasRegistry != DasSourceBrowser.getDasRegistryURL()) { + _initingFetcher=true; + initingThread=Thread.currentThread(); /** * give a visual indication that sequence fetcher construction is occuring */ @@ -85,10 +106,11 @@ public class SequenceFetcher extends JPanel implements Runnable if (guiWindow != null) { guiWindow.setProgressBar("Initialising Sequence Database Fetchers", - Thread.currentThread().hashCode()); + initingThread.hashCode()); } sfetch = sf; - + _initingFetcher=false; + initingThread=null; } return sfetch; } -- 1.7.10.2