The java.util.Map instance and its contents that you place in MDC must be thread safe, preferably immutable, or at least not updated by some other thread after it has placed in MDC.
Log printing, including iteration of the MDC values, happens in another thread (the logger actor) and you probably update Map somewhere else at the same time. You can make a copy of the Map before you pass it to setMDC. I have created an improvement ticket: https://www.assembla.com/spaces/akka/tickets/3866 Regards, Patrik On Thu, Feb 6, 2014 at 2:02 PM, Oleg Zhurakousky <[email protected] > wrote: > Well, you are not creating MDC, rather getting it from 'intmSoapResponse', > so not sure what's going on there and if there are possibilities of another > thread making entries to it. > Also, is it possible that even within the same Actor you may be modifying > MDC from separate threads (e..g, from Future or scheduled task)? > > Cheers > Oleg > > > On Thu, Feb 6, 2014 at 7:40 AM, Kane Lai <[email protected]> wrote: > >> Hi, >> >> I'm using Akka 2.3.0-RC2. >> In my UntypedActor class, I use DiagnosticLoggingAdapter to write logs. >> Randomly my code throws the following exception: >> >> java.util.ConcurrentModificationException: null >> >> at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793) >> ~[na:1.6.0_37] >> >> at java.util.HashMap$EntryIterator.next(HashMap.java:834) ~[na:1.6.0_37] >> >> at java.util.HashMap$EntryIterator.next(HashMap.java:832) ~[na:1.6.0_37] >> >> at >> scala.collection.convert.Wrappers$JMapWrapperLike$$anon$2.next(Wrappers.scala:267) >> ~[scala-library-2.10.3.jar:na] >> >> at >> scala.collection.convert.Wrappers$JMapWrapperLike$$anon$2.next(Wrappers.scala:264) >> ~[scala-library-2.10.3.jar:na] >> >> at scala.collection.Iterator$class.foreach(Iterator.scala:727) >> ~[scala-library-2.10.3.jar:na] >> >> at scala.collection.AbstractIterator.foreach(Iterator.scala:1157) >> ~[scala-library-2.10.3.jar:na] >> >> at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) >> ~[scala-library-2.10.3.jar:na] >> >> at scala.collection.AbstractIterable.foreach(Iterable.scala:54) >> ~[scala-library-2.10.3.jar:na] >> >> at >> scala.collection.TraversableOnce$class.toMap(TraversableOnce.scala:279) >> ~[scala-library-2.10.3.jar:na] >> >> at scala.collection.AbstractTraversable.toMap(Traversable.scala:105) >> ~[scala-library-2.10.3.jar:na] >> >> at akka.event.DiagnosticLoggingAdapter$class.setMDC(Logging.scala:1117) >> ~[akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.event.Logging$$anon$2.setMDC(Logging.scala:567) >> ~[akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at com.kanelai.MyQueueWorker.onReceive(MyQueueWorker.java:140) >> ~[soapqm-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT] >> >> at >> akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167) >> ~[akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.actor.Actor$class.aroundReceive(Actor.scala:465) >> ~[akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97) >> ~[akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.actor.ActorCell.receiveMessage(ActorCell.scala:491) >> [akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.actor.ActorCell.invoke(ActorCell.scala:462) >> [akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) >> [akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at akka.dispatch.Mailbox.run(Mailbox.scala:220) >> [akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at >> akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) >> [akka-actor_2.10-2.3.0-RC2.jar:na] >> >> at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) >> [scala-library-2.10.3.jar:na] >> >> at >> scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) >> [scala-library-2.10.3.jar:na] >> >> at >> scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) >> [scala-library-2.10.3.jar:na] >> >> at >> scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) >> [scala-library-2.10.3.jar:na] >> >> The problematic line is this: >> log.setMDC(intmSoapResponse.getMdc()); >> >> intmSoapResponse is a simple POJO that I can retrieve a MDC HashMap. >> >> Here is how I setup the actor: >> this.ipcQueueWorker = this.getContext().actorOf( >> Props.create(MyQueueWorker.class, getSelf(), queueInfo), >> "MyQueueReceiver"); >> >> Nothing is specified in the akka config file, and therefore the default >> dispatcher is being used. >> >> According to Akka doc ( >> http://doc.akka.io/api/akka/2.3.0-RC2/index.html#akka.event.DiagnosticLoggingAdapter), >> "Only recommended to be used within Actors as it isn't thread safe." Now >> I'm using DiagnosticLoggingAdapter within the actor only. Any idea about >> why I'm still hitting this problem? Is there any other thing I need to take >> care of when using DiagnosticLoggingAdapter? Any suggestion is appreciated! >> Thanks! >> >> >> Kane >> >> -- >> >>>>>>>>>> Read the docs: http://akka.io/docs/ >> >>>>>>>>>> Check the FAQ: http://akka.io/faq/ >> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user >> --- >> You received this message because you are subscribed to the Google Groups >> "Akka User List" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: http://akka.io/faq/ > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/groups/opt_out. > -- Patrik Nordwall Typesafe <http://typesafe.com/> - Reactive apps on the JVM Twitter: @patriknw -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: http://akka.io/faq/ >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/groups/opt_out.
