The Artima Developer Community
Sponsored Link

Java Answers Forum
GC - Thread safe

1 reply on 1 page. Most recent reply: Aug 15, 2009 1:15 PM by Chris Kelly

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Ranjit Radhakrishnan

Posts: 7
Nickname: ranju4all
Registered: Aug, 2009

GC - Thread safe Posted: Aug 13, 2009 12:12 PM
Reply to this message Reply
Advertisement
Is System.gc() thread safe? Please help.

Thanks
RR


Chris Kelly

Posts: 2
Nickname: bigkahuna
Registered: Aug, 2009

Re: GC - Thread safe Posted: Aug 15, 2009 1:15 PM
Reply to this message Reply
As per my understanding the thread that runs the GC is a JVM/System thread.

But more importantly why do you care whether System.gc() is thread safe. If you call System.gc() all you're doing is signalling an intent to the JVM that garbage collection should be performed. Whether or when it happens is another matter.

You can think of System.gc() as an asynchronous call rather than a synchronous one. Just because System.gc() returns, it does not mean that a garbage collection has occured. It just means a request has been made for garbage collection.

Finally System.gc() eventually boils down to a native call so it is system dependent. So you can't really rely on its behaviour from platform to platform.

If you're using System.gc() so that finalize methods get called to clean up resources, then this smells of a bad design because you'll never know exactly when your finalizers are run. The use of finalizers are deemed v.bad practice these days.

Flat View: This topic has 1 reply on 1 page
Topic: Threads for calling procedures Previous Topic   Next Topic Topic: JSP Struts

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use