VariantManagerImpl implements VariantManager { @Override public void allowVariantMultiThreadAccess(boolean allow) { if (allow && !(variantContext instanceof ThreadLocalMultiVariantContext)) { VariantContext newVariantContext = new ThreadLocalMultiVariantContext(); if (variantContext.isIndexSet()) { newVariantContext.setVariantIndex(variantContext.getVariantIndex()); } variantContext = newVariantContext; } else if (!allow && !(variantContext instanceof MultiVariantContext)) { if (variantContext.isIndexSet()) { variantContext = new MultiVariantContext(variantContext.getVariantIndex()); } else { variantContext = new MultiVariantContext(INITIAL_VARIANT_INDEX); } } } VariantManagerImpl(NetworkImpl network); @Override Collection<String> getVariantIds(); int getVariantArraySize(); String getVariantId(int variantIndex); @Override String getWorkingVariantId(); @Override void setWorkingVariant(String variantId); @Override void cloneVariant(String sourceVariantId, String targetVariantId); @Override void cloneVariant(String sourceVariantId, String targetVariantId, boolean mayOverwrite); @Override void cloneVariant(String sourceVariantId, List<String> targetVariantIds); @Override void cloneVariant(String sourceVariantId, List<String> targetVariantIds, boolean mayOverwrite); @Override void removeVariant(String variantId); @Override void allowVariantMultiThreadAccess(boolean allow); @Override boolean isVariantMultiThreadAccessAllowed();  }
@Test public void testMultipleSetAllowMultiThreadTrue() throws Exception { NetworkImpl network = (NetworkImpl) Network.create("testMultipleSetAllowMultiThreadTrue", "no-format"); VariantManager variantManager = new VariantManagerImpl(network); variantManager.allowVariantMultiThreadAccess(true); CountDownLatch cdl1 = new CountDownLatch(1); Exception[] exceptionThrown = new Exception[1]; (new Thread() { public void run() { try { variantManager.allowVariantMultiThreadAccess(true); exceptionThrown[0] = null; } catch (Exception e) { exceptionThrown[0] = e; } finally { cdl1.countDown(); } } }).start(); cdl1.await(); if (exceptionThrown[0] != null) { throw new AssertionError(exceptionThrown[0]); } }