Ask Your Question
0

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(ArrayList.java:782)
    at java.util.ArrayList$Itr.next(ArrayList.java:754)
    at org.ros.message.tf.tfMessage.serialize(Unknown Source)
    at org.ros.message.Message.serialize(Unknown Source)
    at org.ros.internal.message.old_style.MessageSerializer.serialize(MessageSerializer.java:39)
    at org.ros.internal.transport.OutgoingMessageQueue.writeMessageToChannel(OutgoingMessageQueue.java:79)
    at org.ros.internal.transport.OutgoingMessageQueue.access$100(OutgoingMessageQueue.java:38)
    at org.ros.internal.transport.OutgoingMessageQueue$Writer.loop(OutgoingMessageQueue.java:56)
    at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

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
0

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. http://code.google.com/p/rosjava/issues/list

edit flag offensive delete link more
0

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

@Override
        protected void loop() throws InterruptedException
        {
            TFMessage msg = outQueue.take();                    
            publisher.publish(msg);
        }

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

edit flag offensive delete link more

Comments

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

Stats

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

Seen: 190 times

Last updated: Dec 15 '16