ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ConcurrentModificationException in rosjava

asked 2012-03-17 13:51:33 -0500

LawrieGriffiths gravatar image

updated 2016-12-15 05:51:45 -0500

gvdhoorn gravatar image

I am occasionally getting a ConcurrentModificationException exception when running rosjava. It happens when serializing the tfMessage. I am publishing tf messages at 10hz.

The stack trace is:

Exception in thread "pool-1-thread-14" java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(
    at java.util.ArrayList$
    at Source)
    at org.ros.message.Message.serialize(Unknown Source)
    at org.ros.internal.message.old_style.MessageSerializer.serialize(
    at org.ros.internal.transport.OutgoingMessageQueue.writeMessageToChannel(
    at org.ros.internal.transport.OutgoingMessageQueue.access$100(
    at org.ros.internal.transport.OutgoingMessageQueue$Writer.loop(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

Is this a known problem, and is there any way to circumvent it?

I also sometimes getting buffer overflow exceptions in the same code.

This only seems to affect tf messages. I have not seen the problem with any other messages that I am publishing.

I checked out rosjava on March 2nd. I am on Ubuntu 11.10 using ROS electric.

I notice that the stack trace indicates that I am using the old style message serializer. Is there a way to use the new style message serializer?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-03-18 21:16:53 -0500

damonkohler gravatar image

I'm in the process of switching to the new style messaging system. However, it probably won't fix this. Please file an issue with stack trace and any code you can offer to help reproduce the issue.

edit flag offensive delete link more

answered 2016-12-15 04:24:08 -0500

Is it possible that you're invoking publication of TF messages from multiple threads? I would suggest to create a single thread per topic you are publishing on and then interace that one with a BlockingQueue, e.g. LinkedBlockingQueue:

    BlockingQueue<tf2_msgs.TFMessage> outQueue = new LinkedBlockingQueue<tf2_msgs.TFMessage>();

and then in your publisher thread loop something along the lines of

        protected void loop() throws InterruptedException
            TFMessage msg = outQueue.take();                    

This should make the publishing mechanics run in a single thread and protect them from any concurrency issues.

edit flag offensive delete link more


Thanks for taking the time to answer, but this question is 4.5 years old. ROS Electric and the version of rosjava mentioned have long since been EOL-d.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-15 05:51:27 -0500 )edit

The same issue persists with current rosjava, publishers are not thread-safe afaik.

TomRuehr gravatar image TomRuehr  ( 2016-12-15 06:15:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-03-17 13:51:33 -0500

Seen: 314 times

Last updated: Dec 15 '16