bwoogie
bwoogie

Reputation: 4427

What happens to a thread when it ends?

What happens to a thread once it hits the ends? Does it kill itself? or does it float around in memory taking up space? what exactly happens?

new Thread(new Runnable() {
public void run() {
//do some stuff
...

//ok... did some stuff, now what?
}
}).start();

Upvotes: 1

Views: 76

Answers (2)

bingjie2680
bingjie2680

Reputation: 7773

It just simply ends like a normal piece of program. and Garbage Collector can recycle the memory it took. If you want the thread continues to run, you would use it with a while loop or so.

Upvotes: 0

Jarek Potiuk
Jarek Potiuk

Reputation: 20067

It finishes and all it's ThreadLocal objects become eligible for Garbage collection.

Upvotes: 3

Related Questions