Does Junit shut down all the threads?
java, junit, multithreading
Solution
This is actually not JUnit but the external systems which run JUnit test (like Eclipse or Maven) who are responsible for terminating JVM. Those call System.exit which stops all the threads. If JUnit did it then the external system would have no chance to process the results.
Problem
I have a Junit class with 6 tests in them. When the first test runs, it calls one of the methods in my other class which starts a new Thread(). Let's call it `MyThread`. The idea is for `MyThread` to keep running for a bit longer after the JUnit tests are done. For example, for all the JUnit tests to be done, it would take 1 secs, and so I would set `MyThread` to run for 3 secs: ``` new Thread(new Runable(){ public void run(){ System.out.println("start"); Thread.sleep(3000); System.out.println("end"); } }).start(); ``` The `start` would be shown on the standard output, but the `end` is never shown. It seems to me that whenever the JUnit tests are done, `MyThread` is shut down as well. So I am wondering, does JUnit shut down all the threads it initiates? Thanks a lot.