• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

RollingRandomAccessFile Appenter accesses with multiple Threads at the same time

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i´m using log4j2 rc1 Version and hat a problem to write from two threads in an single RollingRandomAccessFile appender.

Here´s my config:

Here´s the error I get:

2014-06-04 10:51:42,347 ERROR Unable to write to stream log/debug/debug_dirk_20140604_105041.log for appender Debug
2014-06-04 10:51:42,348 ERROR An exception occurred processing Appender Debug org.apache.logging.log4j.core.appender.AppenderLoggingException: Unable to obtain lock on log/debug/debug_dirk_20140604_105041.log
at org.apache.logging.log4j.core.appender.FileManager.write(FileManager.java:95)
at org.apache.logging.log4j.core.appender.OutputStreamManager.write(OutputStreamManager.java:129)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:425)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)
at org.apache.logging.log4j.core.Logger.log(Logger.java:112)
at org.apache.logging.log4j.spi.AbstractLogger.debug(AbstractLogger.java:338)
at de.ccw.pep.utils.SleepUtils.safeSleep(SleepUtils.java:61)
at de.ccw.pep.utils.SleepUtils.safeSleep(SleepUtils.java:27)
at de.ccw.pep.service.ServiceTimeManager.waitUntilEndOfServiceTime(ServiceTimeManager.java:221)
at de.ccw.pep.service.ServiceTimeManager.serviceTimeStarted(ServiceTimeManager.java:210)
at de.ccw.pep.service.ServiceTimeManager.observation(ServiceTimeManager.java:199)
at de.ccw.pep.service.ServiceTimeManager.access$0(ServiceTimeManager.java:187)
at de.ccw.pep.service.ServiceTimeManager$1.run(ServiceTimeManager.java:85)
Caused by: java.nio.channels.FileLockInterruptionException
at sun.nio.ch.FileChannelImpl.lock(Unknown Source)
at org.apache.logging.log4j.core.appender.FileManager.write(FileManager.java:88)
... 15 more

Two Threads try to access the log file at the same time.

Do anyone have experience with a situation like this?


Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot share log files between multiple processes or threads. Or, I should say, if you try to share files, the result will be unpredictable.

Solve the problem by having each thread or process write to it's own file.

    Bookmark Topic Watch Topic
  • New Topic