I\'m looking for a way to see the number of currently running threads
In response to your following comment
In the following piece of code: while(resultSet.next()) { name=resultSet.getString("hName"); MyRunnable worker = new MyRunnable(hName); threadExecutor.execute( worker ); } . My thread pool has size of 10. I need to make sure that my program working correctly with multi-threadings & want to check how many threads are running at a certain moment. How can I do this?
to another answer, I suggest that you profile your code with JVisualVM and check if your thread pool is working as it should. The reason behind this suggestion is that then you don't have to bother with all the other housekeeping threads that JVM manages. Besides what you want to do is why tools like JVisualVM are made for.
If you are new to profiling Java programs, JVisualVM lets you see what goes on under the hood while you are running your code. You can see the Heap, GC activity, inspect the threads running/waiting any sample/profile your cpu or memory usage. There are quite a few plugins as well.