• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

GC

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
soumya ravindranath
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jagadesh cs
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting the content Joe. That would explain everything clearly.
reply
    Bookmark Topic Watch Topic
  • New Topic