@Scheduled
causes the code to be run in a separate thread, not necessarily new as it might come from a thread pool.
The non rollover of the log file happens because when log4j tries to rename the file for doing the rollover, some application thread is logging to the file at that precise moment.
According to the code of the log4j rolling file implementation RollingFileAppender, when the time to rollover comes (rollOver()
method called), an attempt is made to rename the file.
if the file is locked then no rollover occurs, and log4j continues to use the same file, until the next time the rollover policy is triggered and a rename is again attempted.
So the @Scheduled
annotations might be contributing to this, but it might not be the only responsible, if there are for example a high volume of requests if it's a web application, etc.
To decrease the likelyhood of rollover failure, try to the change the @Scheduled
threads to run at a different moment than when the rollover attempt occurs.
Also decreasing the logging level to ERROR
will reduce the likelihood of rollover failure. See also How to find which thread is locking a file.