我有一個多線程應用程序,使用log4j進行日誌記錄。當我在我的Windows 7/intel筆記本電腦上測試我的應用程序時,它工作得很好。但是,當我將相同的應用程序部署到生產服務器(solaris/sparc)時,它可以工作10分鐘,然後開始減慢(非常慢)。我使用分析器來查看線程狀態。由於線程轉儲中的log4j操作,阻塞了很多線程。我也使用異步appender,但沒有設法得到任何成功的結果。任何猜測?Log4j Solaris中的多線程處理
這裏有一些轉儲:
"pool-7-thread-105" - Thread [email protected]
java.lang.Thread.State: BLOCKED
at org.apache.log4j.Category.callAppenders(Category.java:204)
- waiting to lock <794f2dae> (a org.apache.log4j.spi.RootLogger) owned by "pool-7-thread-112" [email protected]
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.info(Category.java:666)
"pool-7-thread-112" - Thread [email protected]
java.lang.Thread.State: RUNNABLE
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
- locked <5fcbc329> (a java.io.BufferedOutputStream)
at java.io.PrintStream.write(Unknown Source)
- locked <19e9d0c5> (a java.io.PrintStream)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
- locked <3680c465> (a java.io.OutputStreamWriter)
at java.io.OutputStreamWriter.flush(Unknown Source)
at org.apache.log4j.helpers.QuietWriter.flush(QuietWriter.java:59)
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:324)
at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
- locked <3fddded7> (a org.apache.log4j.ConsoleAppender)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
at org.apache.log4j.Category.callAppenders(Category.java:206)
- locked <794f2dae> (a org.apache.log4j.spi.RootLogger)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.info(Category.java:666)
另外的log4j.xml - 版本1.2.17
<appender name="scripts" class="org.apache.log4j.DailyRollingFileAppender">
<param name="threshold" value="INFO"/>
<param name="file" value="log/script.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern"
value="%-6p[%-d{ISO8601}] [%t] %m (%F:%L) %n"/>
</layout>
</appender>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-6p[%-d{ISO8601}] [%t] %m (%F:%L) %n"/>
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="5000"/>
<appender-ref ref="scripts"/>
</appender>
<root>
<priority value="debug"/>
<appender-ref ref="stdout"/>
<appender-ref ref="ASYNC"/>
</root>
你記錄了多少東西?什麼是日誌記錄?你使用的是什麼版本的log4j? –
我有200個線程在同一時間記錄。我不知道它是否太多或不是,但我知道這在Windows上運行良好。 – MartK
您應該只使用較少的線程。你沒有200個CPU。 –