File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do waiting threads prevent an object's GC ?

 
Vipin Mohan
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

If we call wait() method within the finalize()method of an object, will it prevent the garbage collection of that object till notify() is called ?

Thanks
Vipin
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I imagine it would prevent the collection of any objects, since the finalizer thread will be blocked.

Once, quite early in Java's lifetime, I spent two days trying to understand a deadlock in which one of the two threads involved was the finalizer thread. The subconscious lesson I learned from this was to never do anything non-trivial in finalize() -- this rule has served me well over the years.
 
siva raju
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question dude. As Ernst pointed out, the gc thread will be blocked and no objects marked for finalization in that sweep will be collected until notified. But other gc threads instantiated after this would still run as they are in separate theads.
 
Natarajan Shankar
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vipin,
As your program is still running GC will not colelct your objects. Thats why, if you see program running 24x7 (batch programs). Initially for few times will be ok then later we will have memory problem.
 
Vipin Mohan
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys !
Its clear now.

Cheers
Vipin
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic