@Scheduler是否开始新线程? [英] Does @Scheduler start a new thread?

查看:269
本文介绍了@Scheduler是否开始新线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring应用程序,它有几个预定的方法

I have a Spring application and it has several scheduled methods

似乎Lo4J停止滚动到新文件应用程序运行一段时间后增长到10 GB。

It seems Lo4J stop rolling to new file and grow to 10 Gbytes after the application running for a while.

所有配置看起来都很好,我只使用notepad ++打开日志文件(意味着没有锁定日志按编辑方式编辑)

All configuration looks fine, and I only use notepad ++ to open log file(meaning no lock on log file by editor)

所以我想到可能在应用程序中运行了另一个线程。我想回忆当前应用程序中的任何多线程实现。

So I ponder there might be another thread running in the application. I dong recall any muti-threading implementation in current application.

那么 @Scheduled 方法是否可能导致问题?

Then is it possible that the @Scheduled method causes the issue?

推荐答案

@Scheduled 导致代码运行一个单独的线程,不一定是新的,因为它可能来自线程池。

@Scheduled causes the code to be run in a separate thread, not necessarily new as it might come from a thread pool.

日志文件的非翻转发生是因为当log4j尝试重命名文件以执行rollover,一些应用程序线程在那个精确的时刻记录到文件。

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.

根据log4j滚动文件实现的代码 RollingFileAppender ,当翻转时间来临时( rollOver()方法调用),尝试重命名文件。

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.

如果文件被锁定然后没有发生翻转,并且log4j继续使用同一个文件,直到下次触发翻转策略并再次尝试重命名为止。

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.

所以 @Scheduled 注释可能对此有所贡献,但它可能不是唯一的责任,如果有大量的请求,如果它是一个Web应用程序,等等。

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.

要减少翻转失败的可能性,请尝试更改 @Scheduled 主题,以便在 不同 时刻运行比翻转尝试发生时。

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.

同样将记录级别降低到 ERROR 将降低翻转失败的可能性。另请参见如何查找哪个线程是锁定文件

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.

这篇关于@Scheduler是否开始新线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆