Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

WhizLabs Garbage Collection Question

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
gaurav singhal
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explains why B,C and E are false???
 
Rushikesh Wagh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...........
 
Rahul Ghodeswar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done! I got it.

Thanks Asha.
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic