Ending a Thread

3

When firing multiple% s of% s in a specific loop, at the completion of each, does Thread open in need of a "close" or is it terminated automatically?

for(int i=0;i<=10;i++){
    Process ps = new Process();
    Thread thread = new Thread(ps);
    thread.start();
}

The code above is just an example, because I have a list of processes stored in Amazon AWS SQS, and I need every process found to run in Thread .

    
asked by anonymous 27.12.2016 / 13:26

2 answers

3

When a Thread finishes, it "dies" automatically, and no action is required to finish it.

    
27.12.2016 / 13:36
3

If each message within Sqs is a Thread , it will be terminated at the end of processing, or when you call the interrupt .

But if the processing is too long and it will open many threads, it is ideal to use an executor. It will help you control Threads and prevent you from doing more executions than your support machine.

This link has a better explanation: link

    
27.12.2016 / 16:13