Termination of a Thread

Asked

Viewed 176 times

3

When multiple shots are fired Threads in a specific loop, upon completion of each, the Thread stays open needing a "close" or is automatically finished?

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

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

2 answers

3


When a Thread ends, it "dies" automatically, no action being required to finish it.

3

If every message inside the Sqs for a Thread, it will be terminated at the end of the processing, or when you call the method earth-shattering.

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

In this link there is a better explained example: https://dzone.com/articles/java-concurrency-%E2%80%93-part-7

Browser other questions tagged

You are not signed in. Login or sign up in order to post.