Description
Hi.
It's me again :-) . I now realized that the plugin (which is using your library) prevents the main application to be shutdown gracefully.
I digged the code and figured out that the issue happens when using the DailyRotationPolicy.getInstance()
.
final var config = RotationConfig
.builder()
.file(baseFile)
.filePattern(rolloverFile)
.policy(DailyRotationPolicy.getInstance()) // <-- PROBLEM!
.append(false);
The reason is DailyRotationPolicy
extends TimeBasedRotationPolicy
which invokes the following line in method TimeBasedRotationPolicy#start(Rotatable)
config.getExecutorService().schedule(task, triggerDelayMillis, TimeUnit.MILLISECONDS);
However, this executor service is never subject to be closed. To let my application to shutdown correctly, I need to call the following line in my code:
fos.getConfig().getExecutorService().shutdownNow();
This has been proven as working. But I think the executor service should be closed by your library as it is owned by you. Therefore, I propose to add the line into your RotatingFileOutputStream#close()
; unless you see a better way how to close the executor service properly:
@Override
public synchronized void close() throws IOException {
config.getCallback().onClose(null, config.getClock().now(), stream);
config.getExecutorService().shutdownNow(); // <-- NEW LINE
stream.close();
stream = null;
}
Be aware, this code has not been tested by myself and I do not know if there are not side-effects. I just explained the root cause what is keeping the application running and running and how the potential fix could look like.
Let me know if you need further details. If you prefer a Pull Request just let me know it.
KR, Christoph