Should ClassLoader be thread safe?

I am writing my custom classloader and wondering if I should make it thread safe? As you can easily see, not all native Java class loaders are thread safe, only sun.misc.Launcher.AppClassLoader does (and yet I checked the OpenJDK sources, but this is not the case in OpenJDK).

Is there a reason java class loaders are out of sync? Should custom classloaders be thread safe?

+6
java classloader
source share
1 answer

ClassLoader.loadClass() synchronized.

Typically, a custom classloader will not override this method, but it can override findClass() . Since findClass() is called by loadClass and therefore called from a synchronized critical section, it itself does not need synchronization.

+2
source share

All Articles