How do I get all child threads from a thread in Java?
I'm developing a framework that allows customers to write their own code in Java And this framework invokes its code in a thread (such as thread A) to do custom things.
But customers can create new threads in their code So the question is how to know that all the threads of customer code are completed? Or how to prevent customers from creating threads in their code?
thank you.
Solution
You can create a new ThreadGroup for the client code The activecount method tells you how many client threads are active at a given time, while the enumerate method allows you to enumerate threads To wait for the termination of the entire group, you can enumerate threads and call join. On each thread
If you want to disable the creation of new threads, I believe you can use custom securitymanager to achieve this, but I don't know the details