Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

RollingRandomAccessFile Appenter accesses with multiple Threads at the same time

Posts: 1
  • Mark post as helpful
  • send pies
  • 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(
at org.apache.logging.log4j.core.appender.OutputStreamManager.write(
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(
at org.apache.logging.log4j.core.config.LoggerConfig.log(
at org.apache.logging.log4j.core.config.LoggerConfig.log(
at org.apache.logging.log4j.core.Logger.log(
at org.apache.logging.log4j.spi.AbstractLogger.debug(
at de.ccw.pep.utils.SleepUtils.safeSleep(
at de.ccw.pep.utils.SleepUtils.safeSleep(
at de.ccw.pep.service.ServiceTimeManager.waitUntilEndOfServiceTime(
at de.ccw.pep.service.ServiceTimeManager.serviceTimeStarted(
at de.ccw.pep.service.ServiceTimeManager.observation(
at de.ccw.pep.service.ServiceTimeManager.access$0(
at de.ccw.pep.service.ServiceTimeManager$
Caused by: java.nio.channels.FileLockInterruptionException
at Source)
at org.apache.logging.log4j.core.appender.FileManager.write(
... 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
  • 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.

He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!