Sijo Kurien
Sijo Kurien

Reputation: 135

Will tomcat loads two instances if two classes of the same package exists in classpaths

In one of our production environment we have a messed up structure, The tomcat WEB-INF has ../classes with configurations and ../lib with jars.

We find that the classes directory has a directory following the package structure as below, Sample:

com/test/A.class

Within the lib directory also we have another jar with the same class packaged.

The real issue was looked into when we found that duplicate processing is happening though it is not sure if the issue is because of this.

The actual question is when tomcat starts will two instances of the same class gets created and parallel processing happen? Is it a possibility because both classes directory and lib directory is in the classpath.

Upvotes: 0

Views: 287

Answers (1)

KPS
KPS

Reputation: 31

It is not about tomcat but classloaders. The hierarchy is BootstrapLoader(rt.jar)->ExtensionClassLoader(java.ext.dir location)->ApplicationClassLoader(from application -classpath parameter). So, if the class is loader by any loader from higher hierarchy, it will not get loaded again from any other jar. If you want to load a class from a particular jar without changing the classloading order, please refer to How to load Classes at runtime from a folder or JAR?

Upvotes: 1

Related Questions