1

I think my question is self-explanatory. What will be the quickest and most accurate method of determining that the JVM I use is using multiple class loaders? If it does, What care must be taken to ensure that programs run correctly?

EDIT: I think I needed some clarification around the fact that two classloaders, could they load the same class ? In case of a class like singleton where only a single instance is required how can we prevent it from happening ?

Phoenix
  • 8,695
  • 16
  • 55
  • 88

3 Answers3

2

What care must be taken to ensure that programs run correctly?

For classes, none that I know of. For other application resources (images, help files etc.), use the context class loader.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

I'm struggling with the question.

Every JVM is running multiple classloaders all the time: system classloader, extension classloader, and application classloader at the very least. OSGi, etc.. can add many, many more.

I'm struggling to see any problems here - the whole point of classloaders is isolating namespaces.

Trent Gray-Donald
  • 2,286
  • 14
  • 17
1

Every JVM uses multiple class loaders.

java -XX:+TraceClassLoading -version 2>&1 | cut -d' ' -f2 | grep ClassLoader

prints

java.lang.ClassLoader
sun.reflect.DelegatingClassLoader
java.lang.ClassLoader$3
java.lang.ClassLoader$NativeLibrary
java.security.SecureClassLoader
java.net.URLClassLoader
sun.misc.Launcher$ExtClassLoader
java.lang.ClassLoader$ParallelLoaders
java.net.URLClassLoader$7
sun.misc.Launcher$ExtClassLoader$1
sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$AppClassLoader$1
java.lang.SystemClassLoaderAction

Some of these are inner classes and some extend each other, but there is more than one ClassLoader here and all I did was ask for the version of the JVM.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130