Most likely this is because you're using the maven pid instead of the pid of 
the forked process running your unit test.

Maven forks a subprocess to run your unit tests by default.


On 27/08/2011, at 2:43 AM, Yang wrote:

> I have the following simple code
> 
> 
> 
> import java.util.concurrent.*;
> 
> import org.junit.*;
> 
> /* test whether priorityBlockingQueue provides fairness
> *
> */
> public class BlahTest {
> 
>  @Test
>  public void blahTest() throws Exception {
>    ExecutorService exec = Executors.newCachedThreadPool();
>    for(int i=0;i<100;i++) {
>      exec.submit(
>          new Thread() {
>            public void run() {
> 
>              try {
>                Thread.sleep(10000000);
>              } catch (InterruptedException e) {
>                // TODO Auto-generated catch block
>                e.printStackTrace();
>              }
>            }
>          }
>          );
>    }
> 
>    Thread.sleep(30000);
>    exec.shutdown();
>  }
> }
> 
> 
> 
> 
> if I run this with "maven test", and I do a jstack, I see only 5
> threads in the pool, instead of the 100 that I'm expecting. indeed if
> I run it with java -cp MY_CP:blah:blah  org.junit.runner.JUnitCore
> BlahTest
> 
> then jstack does show 100 threads
> 
> 
> why is this?
> 
> the pom.xml is attached here if you want to test it out
> 
> 
> <project xmlns="http://maven.apache.org/POM/4.0.0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd";>
>  <modelVersion>4.0.0</modelVersion>
>  <artifactId>blah</artifactId>
>  <groupId>blah</groupId>
>  <packaging>jar</packaging>
>  <version>0</version>
>  <name>blah</name>
> 
>  <build>
>    <plugins>
>        <plugin>
>            <groupId>org.apache.maven.plugins</groupId>
>            <artifactId>maven-compiler-plugin</artifactId>
>            <configuration>
>                <source>1.6</source>
>                <target>1.6</target>
>            </configuration>
>        </plugin>
>    </plugins>
>  </build>
> 
>  <dependencies>
>    <dependency>
>      <groupId>junit</groupId>
>      <artifactId>junit</artifactId>
>      <version>4.8.2</version>
>      <scope>test</scope>
>    </dependency>
>  </dependencies>
> </project>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to