• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Do waiting threads prevent an object's GC ?

 
Ranch Hand
Posts: 79
  • 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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
Ranch Hand
Posts: 37
  • 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.
 
Ranch Hand
Posts: 53
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys !
Its clear now.

Cheers
Vipin
 
rubbery bacon. rubbery tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic