[concurrency-interest] Thread safety when loading and linkingclasses

David Holmes davidcholmes at aapt.net.au
Wed Apr 22 17:49:24 EDT 2009


The simple answer is that "yes it should all be thread-safe". But there is a
more complex answer that can lead to problems in some complex circumstances.
In short the VM doesn't expect/assume that ClassLoader implementations are
thread-safe, so it uses synchronization on the ClassLoader instance to
ensure that. But that can lead to potential deadlocks if class-loaders don't
obey strict delegation, so there are some hacks that can be employed to
avoid this.

If you have more specific details on the problem drop me a direct email and
I'll see if I can match the symptoms to any known issues.

David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Peter
> Kovacs
> Sent: Thursday, 23 April 2009 1:10 AM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] Thread safety when loading and
> linkingclasses
> Hi,
> Is the Class.forName(String) call thread-safe? Must the underlying
> ClassLoader instances be thread safe or is their thread-safety
> guaranteed "automagically" by the JVM? If ClassLoader instances must
> be thread-safe, is the default application class loader known to be
> thread-safe? (Based on the reference to JLS 12.4.2 in JCIP 3.5.3,
> there appears to be fairly strong guarantees about the thread-safety
> of class initialization, but it is not immediately clear to me whether
> similar guarantees can be assumed about the loading and liking phase
> as well.)
> (We're having a rare random problem and [short of any better, more
> realistic candidate] Class.forName(String) has come under suspicion.)
> Thanks
> Peter
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list