I need to close some streams when my Java EE app is undeployed to avoid pages of exceptions in the server.log every time I undeploy. The Exceptions say: “Input stream has been finalized or forced closed without being explicitly closed”. I know how to close (with the close() method), but I dont know when.
finallize() comes too late, @PreDestroy is called not only before undeploying but also in normal operation mode. How does the app know, when it is undeployed?
Edit:
I call this during creation:
decisionLogger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(
ksession,
config.getString("rules.logfilename"),
config.getInt("rules.loginterval"));
decisionLogger is of type KnowledgeRuntimeLogger which has only the close() method. No getter for the thread that works under the hood. To shut it down gently, I need to call the close method, but when?
Add a finalize() method to the logger or whichever class is causing the issues. Close the streams from that. Unless you exit with System.exit() it will run. If System.exit is being called you can use Runtime.addShutdownHook