Click here to Skip to main content
15,885,772 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.

I would like to ask you a question. Is it bad practice to use threads in thread? Something like:

Java
 Thread bigThread=new Thread(){
     public void run(){

        //do something here
        PersonalThread pThread=new PersonalThread(); //class wich extends Thread class, and implements run() method
        pThread.start();
        try{
        pThread.join();
        }catch(InterruptedException e){

        }

     }


}
bigThread.start();


Thank you for comment or response.
Posted

1 solution

In principle there is no issue with starting threads from other threads. There's no parent child relation between Threads! There's no big advantage calling a thread inside another!
The most important thing is that you might run into the point where creating more threads creates contention (due to context switching overhead and perhaps locking) making things slow.
 
Share this answer
 
Comments
nameJulian 13-May-13 8:27am    
Well in my application, i'm creating the big thread when i click a button, and then the big thread creates a number of threads. ( and the number of how many threads need to be created is taken from an ArrayList.size() ).
Jayarajantk 13-May-13 8:36am    
This is something like calling many threads from the main application, right? You can make as many threads as you need but the basic thing is already explained.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900