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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

RollingRandomAccessFile Appenter accesses with multiple Threads at the same time

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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?

regards

dbausnnd
 
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!