[英]System.out.println in static initializer apparently outputting twice
In my application deployed on Tomcat, there is a class as follows: 在我在Tomcat上部署的应用程序中,有一个类如下:
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class ServiceEndpointApplication extends Application {
final static String LOGGER_NAME = "test";
static {
System.out.println("static init start");
Logger logger = Logger.getLogger(LOGGER_NAME);
logger.setLevel(Level.OFF);
System.out.println("static init end");
}
...
}
Just after starting up Tomcat, I send 50 reqests by using JMeter (50 threads, 1 ramp-up period, 1 loop). 在启动Tomcat之后,我使用JMeter发送了50个请求(50个线程,1个加速期,1个循环)。
Then tail -f catalina.out
shows the following logs: 然后tail -f catalina.out
显示以下日志:
Nov 06, 2018 1:36:57 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 64126 ms
static init start
static init end
static init end
static init end
is shown twice! static init end
显示两次!
This behavior happens at a probability of about 10%. 这种行为发生的概率约为10%。
My Question : 我的问题 :
What are possible reasons for this strange behavior? 这种奇怪行为的可能原因是什么?
Environment : 环境 :
Java Java的
Tomcat 7.0.59 Tomcat 7.0.59
I found out the reason. 我发现了原因。 This is caused by -f
option of tail
command. 这是由tail
命令的-f
选项引起的。
I reproduced this behavior: 我重现了这个行为:
$ tail -f catalina.out
...
Nov 06, 2018 7:18:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 62601 ms
static init start
static init end
static init end
And then I ran tail
without any options: 然后我没有任何选择跑tail
:
$ tail catalina.out
...
Nov 06, 2018 7:18:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 62601 ms
static init start
static init end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.