I am using someone else's code that uses Watchmaker to get a concrete business result.
The original code I am using was triggered by a Runnable class.
I modified the class into a Callable and created a wrapper that was using an ExecutiveService and submitting this new Callable to the ExecutiveService every time a new HttpRequest arrived from a web-client.
To test this setup I created 2 HTTP requests within a JUNIT test class and sent them to the new wrapper.
Once the test completes the clean up code shuts down the HTTPserver (during test setup the code starts an HTTP server and REST end points )
Everything worked as expected expect after the test I got 8 warnings, one per FitnessEvaluationWorker thread:
Dec 04, 2017 12:03:37 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application appears to have started a thread named [FitnessEvaluationWorker0-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(Unknown Source)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
I snooped around and found out that each of the FirnessEvaluationWorker threads was in the WAITING state. An attempt to close all 8 threads threw IllegalMonitorState exception, one per Thread.
I contacted the developer who created original code and he told me that Watchmaker was not giving away any shutdown hooks I could execute during HTTP server shutdown.
We run our tests on Jenkins and I do not want to leave behind any threads after executing my tests.
Any advice?
Thanks