GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes WhizLabs Garbage Collection Question 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 "WhizLabs Garbage Collection Question" Watch "WhizLabs Garbage Collection Question" New topic
Author

WhizLabs Garbage Collection Question

Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi guys,

Can anyone confirm whether daemon thread is charged on the SCJP 5 exam ?

I simply missed the below question because I don't know about daemon threads.


Which of the following statements is/are true ?

a) Garbage collection is performed by a low priority daemon thread.

b) Garbage collection always use a mark and sweep algorithm

c) The finalize() method is invoked for objects in the order in which they were created.

d) The finalize method is tipically used to free up resources other than memory.

e) Objects that are created and acessed locally within a method , are eligible for garbage collection when the method returns.

I chose D but according to WhizLabs explanation the correct answer is A and D

Thanks.


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
gaurav singhal
Ranch Hand

Joined: Nov 18, 2005
Posts: 135
Can anybody explains why B,C and E are false???
Rushikesh Wagh
Ranch Hand

Joined: Jun 18, 2005
Posts: 58
B) is defenetly Wrong. We can not firmly say that JVM uses [b]always use a mark and sweep algorithm[b] it is totally upto JVM Which kind of algorithm he uses for garbage collection.
C) The finalize() method is invoked for objects in the order in which they were created. ... its supid sentence just ask JVM Man. Cause he is only Responsible 4 these kind of issuses. He is strict. We can not perdict Him....
D) is also wrong. The finalize method is tipically used to free up memory resources...........
E) is also wrong. Because if we return the refrence of object created in method then the object is not eligiable for garbage collection.
But Guys Concentrate on [b]acessed locally within a method....[b] If it is only used in method itself then its eligiable for garbage collection.


A is True. Its Daemon Thread. And It usually gets Run Only When Reqd. i.e. it has low priority. But we Can not firmly Say that when it run.
we can use System.gc() But dont force JVM. He Decides what do with it...........


Best Regards,
Rushikesh Wagh
SCJP 1.4 (2005)
SCJP 1.6 (2010)
Rahul Ghodeswar
Greenhorn

Joined: Mar 06, 2006
Posts: 6
Hi Rushikesh,
D) is also wrong. The finalize method is tipically used to free up memory resources...........


I dont think this is correct. Finalize method is typically used to free resources other than memory, since memory will be freed by the Garbage colletctor.

Hence both A & D are correct options.


Thanks,<br />Rahul<br /> <br />----------------------------------<br />If you really want something, then whole universe conspires to make it happen.<br />-----------------------------------
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
What Rahul said about option D is correct. It's the same explanation given by WhizLabs.

Concerning option E, another reason to be incorrect is that even your method does not return the reference it used, this method still can pass this reference to another active thread. So, option D is definitelly wrong.

Now that we understand the why that options B, C and E are wrong, can anyone please give me a brief explanation about "What's daemon threads and how are they used by garbage collection ?"
Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
Hi Edisandro,

Daemon threads are designed as service providers for other threads in the same process space as the deamon thread.These are low-level background threads that perform useful work for the other threads. However, it is not essential that they be allowed to complete before an application terminates.

Like downloading of stock prices, but if the application doing analysis of these stock prices stops then there is no need to download the prices.

Deamon threads are stopped as soon as the application that needed their service stops or exits.

Regards
Asha


SCJP 1.5
Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
But don't worry deamon threads are not on the exam, but you must always remember that GC is run by a low-level deamon thread so that it doesn't block our threads from running.

Regards
Asha
Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
But don't worry deamon threads are not on the exam, but you must always remember that GC is run by a low-level deamon thread so that it doesn't block our threads from running.

Regards
Asha
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
I'm not sure that anyone can reliably say that on all JVM's the garbage collector will be run on a low priority deamon thread. That's probably true most of the time, but I don't think it's in the spec. (Now I'm stepping in it, okay bring it on )

In any case, the exam WON'T ask you anything like this - the key points on the exam are that you can't force the GC you can only make a request, and that you don't know for sure what algorithm the GC will use.
[ April 07, 2006: Message edited by: Bert Bates ]

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Well done! I got it.

Thanks Asha.
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Thanks Bert. I will burn it in my brain.

By the way, I've just sent an email to you and Kathy. Could you please check it out ?

Thanks.
 
GeeCON Prague 2014
 
subject: WhizLabs Garbage Collection Question