Folks,This is probably not a Tomcat issue, but any thoughts on how to resolve this would be greatly appreciated.
I am running into an apparent ClassLoader leak with the following configuration:
Windows 10 Professional (64 bit, latest updates)
OpenJDK 11.0.10
Apache Tomcat 7.0.107
Jersey Rest 2.33
I have a simple application:
ApplicationConfig:
@ApplicationPath("/service")
public class ApplicationConfig extends Application {
public ApplicationConfig() {
}
@Override
public Set<Class<?>> getClasses(){
Set<Class<?>> resources = new java.util.HashSet<>();
resources.add(org.mdeggers.cplanapi.resource.CostInfoResource.class);
resources.add(org.mdeggers.cplanapi.resource.InstituteInfoResource.class);
resources.add(org.mdeggers.cplanapi.resource.InstituteTypeInfoResource.class);
resources.add(org.mdeggers.cplanapi.mapper.NotFoundExceptionMapper.class);
return resources;
}
}
One of three resources:
@Path("/v1/inst")
public class InstituteInfoResource {
public InstituteInfoResource() {
}
@GET
@Path("/info")
@Produces({MediaType.APPLICATION_JSON})
public InstituteContainer getNationalList() {
InstituteInfo instituteinfo = new InstituteInfo();
return instituteinfo.getNational();
}
@GET
@Path("/info/{ state : [A-Z]{2} }")
@Produces({MediaType.APPLICATION_JSON})
public InstituteContainer getStateList(@PathParam("state") String
state) {
InstituteInfo instituteinfo = new InstituteInfo();
return instituteinfo.getState(state);
}
}
The InstituteInfo class is a DAO that makes requests into a MySQL
database and returns a container with the information.
This all works, but on undeploying the Tomcat Manager complains that there is a leak after unloading the web application.
Doing a heap dump and looking at it with the following OQL in Eclipse MAT shows that the application still resides in memory, with started=false.
SELECT wcl.contextName.toString() AS contextName,
wcl.started AS started,
wcl.@retainedHeapSize AS retainedSize
FROM org.apache.catalina.loader.WebappClassLoader wcl
contextName started retainedSize
/cplanapi false 586,720
/docs true 46,664
/host-manager true 47,288
/manager true 47,392
/examples true 85,432
true 46,912
GC roots for cplanapi are:
class com.sun.naming.internal.ResourceManager
'- propertiesCache java.util.WeakHashMap
'- table java.util.WeakHashMap$Entry[16]
'- java.util.WeakHashMap$Entry
'- referent org.apache.catalina.loader.WebappClassLoader
This occurs on both Windows and Linux, and with the above JRE as well as
Java 1.8.0_202.
. . . just my two cents /mde/
OpenPGP_signature
Description: OpenPGP digital signature
