[concurrency-interest] Thread safety when loading and linkingclasses

Péter Kovács peter.kovacs.1.0rc at gmail.com
Thu Apr 23 07:14:20 EDT 2009

Thank you, David!

After our code was corrected to pass on an exception which in the
previous version had been transformed into a meaningless
NullPointerException, it turned out that the thread executing
Class.forName was interrupted. (It is still a mystery who did the
interrupt, but it doesn't appear to make much sense to hunt around for
the interrupter as the code appears to be still in some kind of early
alpha version...)


On Wed, Apr 22, 2009 at 11:49 PM, David Holmes <davidcholmes at aapt.net.au> wrote:
> Peter,
> 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.
> Cheers,
> 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