I am trying to test an application with Jmeter. The application uses a proprietary library that creates multiple threads. In JMeter I have created a AbstractJavaSamplerClient, which does not seem to wait for all the other threads that might be generated in the application. Instead it just runs its own default method and closes leaving the other threads running in the background - since I am connecting to a server in the application, I can see through the server logs that it is still connected. Since I don't have the references to the other threads as they are instantiated through the proprietary library, I can't use the common solutions of wait() or join().How can I get the main thread to wait for all the threads (none of which I have references too)?
Asked
Active
Viewed 113 times
2 Answers
3
Put all work with the library in a separate thread in a specially created thread group. The library will create new threads in that thread group and its descendants. List all threads of that group recursively with group.enumerate(new Thread[group.activeCount()*2],true)
. Then you can join() them all.

Alexei Kaigorodov
- 13,189
- 1
- 21
- 38
-
1The "trick" with `activeCount()*2` is good, but to be correct one has to check whether the return value of enumerate is strictly less than the given length (strictly because if it's exactly the same size you can't distinguish the case of too small a size from one that just fits perfectly). Yeah it's kind of an awkward API to use. – Voo Feb 26 '14 at 11:47
1
You can start with
Thread.getAllStackTraces().keySet();
which will give you a set of all running threads. This will include those you are interested in and all the other threads, including those internal to the JVM.
Hopefully you'll be able to filter out the ones you are interested in by name, and then you can join()
them.

Marko Topolnik
- 195,646
- 29
- 319
- 436
-
Thanks for the solution. However, I proceeded with Alexei's solution. – Wahaj Ali Feb 26 '14 at 12:23
-