When does a Java thread actually get cleaned up?
Question:
If I start a java thread from the 搈ain?thread of execution and that thread I just created finish抯 executing its 搑un?method is that threads resources automatically clean up? Or do we have to do this clean up ourselves?
Is the under the hood thread stuff cleaned up or do we need to call the join method or some other method?
[354 byte] By [
tinnya] at [2007-11-27 5:19:26]

> Question:
>
> If I start a java thread from the 搈ain?thread of
> execution and that thread I just created finish抯
> executing its 搑un?method is that threads resources
> automatically clean up? Or do we have to do this
> clean up ourselves?
Depends which resources you mean. There's nothing special about threads in that respect.
Memory is automatically reclaimed when it is no longer reachable, so unless the run method set some member variables in some object that remains reachable after it completes, no worries there.
Files, sockets, etc. remain open unless you close them.
jverda at 2007-7-12 10:42:48 >

> Is there any associated control block information in
> a thread (e.g. stack info? (Like a Process Control
> Block is associated with each process in a muti
> tasking operating system).
Probably.
>
> If so is this control block information automatically
> cleaned up when the run method is finished?
Yes.
jverda at 2007-7-12 10:42:48 >
