The problem:
Deploying the XCC library with a WAR file (in WEB-INF/classes) prohibits re-deployments/updates of that webapp without restarting the whole Tomcat container. It just stops working, because there are still resources allocated and therefore some JAR files could not be removed by Tomcat.
When deploying the library in Tomcats lib directory (as a JDBC driver would be), Tomcat writes memory leak warnings in Tomcat log as followed:
17-Mar-2016 10:58:45.683 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [api] appears to have started a thread named [Thread-4] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method) com.marklogic.xcc.ContentSourceFactory$ConnectionCollector.run(ContentSourceFactory.java:449)
What I found out:
I did some investigation and found out, that (at least in XCC 8.0.3) there is a thread started in the ContentSourceFactory that is never shut down. That thread is affecting updates/re-deployments of servlets and creates memory leaks. My quick-win solution was to create a custom ContentSourceFactory, having a shutdown method which gets called when the servlet stops.
The question:
Unfortunately I didn't find any clues in the documentation. So whats the official way to use the XCC library (8.x) in a servlet container?