File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC" Watch "GC" New topic
Author

GC

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
some qns related to GC

1) is the Static Objects eligible for the eligibilization of GC.


2) can we overload Finalize.


3)THe thread for which the run method completes or it exits the program is considered as the Dead Thread.
All the other thread are considered live thread i.e other states like block,wait...



4)The GC will run when needed irrespective whether the user invokes it or not?
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961

1) is the Static Objects eligible for the eligibilization of GC.


There is not such thing as static objects, just static references to objects. Both static variables and instance variables could reference the same object. When such object is unreachable by any means, it will be elegible for gc, just as any other object.

About finalization here's an example:



Just make sure to call super.finalize(). Because the finalize method is not like the constructor, wich call parent constructors automatically.


3)THe thread for which the run method completes or it exits the program is considered as the Dead Thread.


I thinks that's right!


All the other thread are considered live thread i.e other states like block,wait...


I think that's not true. A thread is alive only after its start method have been called and befored its run method has completed.


4)The GC will run when needed irrespective whether the user invokes it or not?


Not absolutlely true, you could run a program and gc could never run, simple because the conditions to be run were never met. However if it has to run you can do nothing to help it.
[ April 26, 2005: Message edited by: Edwin Dalorzo ]
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
hi,

you can overload the finalize method, but still the original one will be called.
so, for whatever reason you would like to do this for, you would at least need to overide the finalize method in order to manually call your overloaded one.

Alex.
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
Originally posted by Edwin Dalorzo:

All the other thread are considered live thread i.e other states like block,wait...


I think that's not true. A thread is alive only after its start method have been called and befored its run method has completed.



But a thread will go in to block or wait only after it starts, isn't it ?
Jagadesh cs
Ranch Hand

Joined: Apr 25, 2005
Posts: 50
As long as thread's run method is not completed , no matter if it is in wait blocked or any thing , it is still eligible to run and it is alive


Cheers,<br />Jagadesh.<br /> <br />--------------------------------<br />SCJP 1.4 , SCBCD 1.3 , SCWCD 1.4<br />--------------------------------
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
After start() has been called, the thread enters the "ready to run" state. The thread may enter the "running" state at the discretion of the thread scheduler which is completely indeterminate.

On a related note,
http://qa.jtiger.org/GetQAndA.action?qids=51


Tony Morris
Java Q&A (FAQ, Trivia)
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
Originally posted by Tony Morris:
After start() has been called, the thread enters the "ready to run" state. The thread may enter the "running" state at the discretion of the thread scheduler which is completely indeterminate.

On a related note,
http://qa.jtiger.org/GetQAndA.action?qids=51


Nevertheless, that a thread in wait or blocked state is a live thread is true, or ?
Jagadesh cs
Ranch Hand

Joined: Apr 25, 2005
Posts: 50
Yes unless a thread is dead it is always alive !!! ( even if its in blocked / waiting /sleeping or any thing )

This fact is also mentioned in K & B chapter on threads ( different states of a thread ). You can refer it in case you need more explanation.
Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
Yes, a thread in a blocked/waiting/sleeping state is alive, according to K&B p. 507.

The 5 states of a thread:
New: before start() is called. not alive
Runnable: after start() is called, and also after returning from a blocked/waiting/sleeping state. alive
Running: thread scheduler has selected this thread to run from the runnable pool and the thread is currently executing its run method. alive
Waiting/blocked/sleeping: thread is alive but is not currently eligible to run, although it may return to being runnable later. It's either blocked trying to get in a synchronized block or waiting for a resource, or it's sleeping because the code told it to sleep, or it's waiting because the code told it wait for notification. alive
Dead: run method has completed. Thread object still exists, but the thread of execution can not be started again. not alive


SCJA 1.0 (98%), SCJP 1.4 (98%)
Jagadesh cs
Ranch Hand

Joined: Apr 25, 2005
Posts: 50
Thanks for posting the content Joe. That would explain everything clearly.
 
Don't get me started about those stupid light bulbs.
 
subject: GC