JAL-1681 work around ConcurrentModificationException on startup
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 13 Apr 2015 15:03:23 +0000 (16:03 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 13 Apr 2015 15:03:23 +0000 (16:03 +0100)
src/jalview/workers/ComplementConsensusThread.java

index 2e4424e..71bfb40 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.workers;
 
+import java.util.ConcurrentModificationException;
 import java.util.Hashtable;
 
 import jalview.analysis.AAFrequency;
@@ -37,13 +38,31 @@ public class ComplementConsensusThread extends ConsensusThread
     return alignViewport.getComplementConsensusHash();
   }
 
+  /**
+   * Calculate the cDNA consensus and store it on the Viewport
+   */
   @Override
   protected void computeConsensus(AlignmentI alignment)
   {
     Hashtable[] hconsensus = new Hashtable[alignment.getWidth()];
 
     SequenceI[] aseqs = getSequences();
-    AAFrequency.calculateCdna(alignment, hconsensus);
+
+    /*
+     * Allow 3 tries at this, since this thread can start up while we are still
+     * modifying protein-codon mappings on the alignment
+     */
+    for (int i = 0; i < 3; i++)
+    {
+      try
+      {
+        AAFrequency.calculateCdna(alignment, hconsensus);
+        break;
+      } catch (ConcurrentModificationException e)
+      {
+        // try again
+      }
+    }
 
     alignViewport.setComplementConsensusHash(hconsensus);
   }