我们在单个物理主机上运行多个应用程序实例(每个 tomcat 服务器一个)。应用程序做体面的日志记录。最近我们观察到一些应用程序变慢或挂起,需要重新启动。在线程转储中,发现所有线程在日志语句上都被 BLOCKED,等待锁定println
对象。和其他一些对象已经锁定println
。但我不明白为什么其他线程没有释放println
对象上的锁?我粘贴了一些线程转储快照:
阻塞的线程转储:
java.lang.Thread.State: BLOCKED (on object monitor)
at java.io.PrintStream.println(PrintStream.java:755)
- waiting to lock <0x00000007830097e0> (a java.io.PrintStream)
at org.apache.tomcat.util.log.SystemLogHandler.println(SystemLogHandler.java:238)
at com.webaroo.smsnew.common.SMSUtils.log(SMSUtils.java:167)
at com.webaroo.smsnew.common.SMSUtils.log(SMSUtils.java:113)
记录 println 的线程的线程转储。
java.lang.Thread.State: BLOCKED (on object monitor)
at java.nio.CharBuffer.wrap(CharBuffer.java:350)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:246)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
- locked <0x00000007830098f0> (a java.io.OutputStreamWriter)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
- locked <0x00000007830098f0> (a java.io.OutputStreamWriter)
at java.io.PrintStream.write(PrintStream.java:476)
- locked <0x00000007830097e0> (a java.io.PrintStream)
at java.io.PrintStream.print(PrintStream.java:619)
at java.io.PrintStream.println(PrintStream.java:756)
- locked <0x00000007830097e0> (a java.io.PrintStream)
at org.apache.tomcat.util.log.SystemLogHandler.println(SystemLogHandler.java:238)