0

I am writing an adapter to use chronicle queue in Apache Aries Remote Service Admin. It works fine when I only use a single thread. With more than one thread I get exceptions like below.

Any idea what i do wrong?

For reference this is my code: https://github.com/cschneider/rsa-chronicle-provider/blob/master/src/test/java/org/apache/aries/rsa/provider/chronicle/ChronicleProviderTest.java

You can see the exception if you increase the number of threads in the executor.

Exception in thread "pool-3-thread-2" java.nio.BufferOverflowException
    at net.openhft.chronicle.bytes.AbstractBytes.writePosition(AbstractBytes.java:182)
    at net.openhft.chronicle.bytes.AbstractBytes.writePosition(AbstractBytes.java:29)
    at net.openhft.chronicle.wire.AbstractWire.writeHeader0(AbstractWire.java:183)
    at net.openhft.chronicle.wire.AbstractWire.writeHeader(AbstractWire.java:171)
    at net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts$StoreAppender.append(SingleChronicleQueueExcerpts.java:252)
    at net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts$StoreAppender.writeBytes(SingleChronicleQueueExcerpts.java:153)
    at org.apache.aries.rsa.provider.chronicle.ChronicleInvocationHandler.invoke(ChronicleInvocationHandler.java:45)
    at com.sun.proxy.$Proxy7.callOneWay(Unknown Source)
    at org.apache.aries.rsa.provider.chronicle.ChronicleProviderTest$1.run(ChronicleProviderTest.java:87)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64

1 Answers1

1

Looks like Chronicle appenders are not thread safe so writes to the same queue must be synchronized.

See FAQ: Can I have multiple writers?

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • 1
    Or you need an appender for each thread. When you acquire an appender for a queue you get a thread local appender that thread can use safely but if you pass it between queues you must lock it. – Peter Lawrey Feb 05 '17 at 06:06