Source:
<code>public void validatesMultipleXmlsInThreads() throws Exception { final int zero = 0; final int ten = 10; final int hundred = 100; final int fifty = 50; final XSD xsd = new XSDDocument( StringUtils.join( "<xs:schema xmlns:xs ='<LINK_0>' >", "<xs:element name='r'><xs:complexType><xs:sequence>", "<xs:element name='x' maxOccurs='unbounded'><xs:simpleType>", "<xs:restriction base='xs:integer'>", "<xs:maxInclusive value='100'/></xs:restriction>", "</xs:simpleType></xs:element>", "</xs:sequence></xs:complexType></xs:element></xs:schema>" ) ); final Random rnd = new SecureRandom(); final XML xml = new XMLDocument( StringUtils.join( Iterables.concat( Collections.singleton("<r>"), Iterables.transform( Collections.nCopies(ten, zero), new Function<Integer, String>() { @Override public String apply(final Integer pos) { return String.format( "<x>%d</x>", rnd.nextInt(hundred) ); } } ), Collections.singleton("<x>101</x></r>") ), " " ) ); final AtomicInteger done = new AtomicInteger(); final Callable<Void> callable = new Callable<Void>() { @Override public Void call() throws Exception { try { new StrictXML(xml, xsd); } catch (final IllegalArgumentException ex) { done.incrementAndGet(); } return null; } }; final ExecutorService executorService = Executors.newFixedThreadPool(5); for (int count = zero; count < fifty; count = count + 1) { executorService.submit(callable); } <START> executorService.awaitTermination(ten, TimeUnit.SECONDS); <END> executorService.shutdown(); MatcherAssert.assertThat(done.get(), Matchers.equalTo(fifty)); }</code><technical_language>@tmjee shutdown awaitTermination shutdownNow</technical_language>

Target:
public void validatesMultipleXmlsInThreads() throws Exception { final int timeout = 10; final int numrun = 100; final int loop = 50; final XSD xsd = new XSDDocument( StringUtils.join( "<xs:schema xmlns:xs ='<LINK_0>' >", "<xs:element name='r'><xs:complexType><xs:sequence>", "<xs:element name='x' maxOccurs='unbounded'><xs:simpleType>", "<xs:restriction base='xs:integer'>", "<xs:maxInclusive value='100'/></xs:restriction>", "</xs:simpleType></xs:element>", "</xs:sequence></xs:complexType></xs:element></xs:schema>" ) ); final Random rnd = new SecureRandom(); final XML xml = new XMLDocument( StringUtils.join( Iterables.concat( Collections.singleton("<r>"), Iterables.transform( Collections.nCopies(timeout, 0), new Function<Integer, String>() { @Override public String apply(final Integer pos) { return String.format( "<x>%d</x>", rnd.nextInt(numrun) ); } } ), Collections.singleton("<x>101</x></r>") ), " " ) ); final AtomicInteger done = new AtomicInteger(); final Callable<Void> callable = new Callable<Void>() { @Override public Void call() throws Exception { try { new StrictXML(xml, xsd); } catch (final IllegalArgumentException ex) { done.incrementAndGet(); } return null; } }; final ExecutorService executorService = Executors.newFixedThreadPool(5); for (int count = 0; count < loop; count = count + 1) { executorService.submit(callable); } executorService.shutdown(); MatcherAssert.assertThat( executorService.awaitTermination(timeout, TimeUnit.SECONDS), Matchers.is(true) ); executorService.shutdownNow(); MatcherAssert.assertThat(done.get(), Matchers.equalTo(loop)); }