From be9e1fcba78dac8c9fb39df89c0105a2a2ceca99 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 6 Nov 2015 18:05:09 +0300 Subject: [PATCH] thread leaks --- .../util/xml/DomConcurrencyStressTest.java | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java index c625a6a2070a..82f2f804c5c8 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java @@ -27,7 +27,10 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.semantic.SemService; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.Timings; +import com.intellij.util.Function; +import com.intellij.util.Processor; import com.intellij.util.TimeoutUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xml.impl.DomFileElementImpl; import com.intellij.util.xml.impl.DomTestCase; import com.intellij.util.xml.reflect.DomExtender; @@ -35,6 +38,7 @@ import com.intellij.util.xml.reflect.DomExtenderEP; import com.intellij.util.xml.reflect.DomExtensionsRegistrar; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.CountDownLatch; @@ -115,27 +119,42 @@ public class DomConcurrencyStressTest extends DomTestCase { for (int i=0; i exc = Ref.create(null); - final CountDownLatch reads = new CountDownLatch(8); - for (int j = 0; j < 8; j++) { - new Thread("dom concurrency"){ - @Override - public void run() { - try { - runnable.run(); + int N = 8; + final CountDownLatch reads = new CountDownLatch(N); + List threads = ContainerUtil.map(Collections.nCopies(N, ""), new Function() { + @Override + public Thread fun(String s) { + return new Thread("dom concurrency") { + @Override + public void run() { + try { + runnable.run(); + } + catch (Throwable e) { + exc.set(e); + } + finally { + reads.countDown(); + } } - catch (Throwable e) { - exc.set(e); - } - finally { - reads.countDown(); - } - } - }.start(); - } + }; + } + }); + ContainerUtil.process(threads, new Processor() { + @Override + public boolean process(Thread thread) { + thread.start(); + return true; + } + }); + reads.await(); if (!exc.isNull()) { throw exc.get(); } + for (Thread thread : threads) { + thread.join(); + } } }