写入具有多个线程的编年史队列 - > java.nio.BufferOverflowException

时间:2016-03-29 08:05:51

标签: chronicle chronicle-queue

我正在编写一个适配器来在Apache Aries远程服务管理中使用chronicle队列。当我只使用一个线程时,它工作正常。有多个线程我得到如下的异常。

知道我做错了吗?

供参考,这是我的代码: https://github.com/cschneider/rsa-chronicle-provider/blob/master/src/test/java/org/apache/aries/rsa/provider/chronicle/ChronicleProviderTest.java

如果增加执行程序中的线程数,则可以看到异常。

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)

1 个答案:

答案 0 :(得分:1)

看起来Chronicle appender不是线程安全的,因此必须同步写入同一队列。

请参阅FAQ: Can I have multiple writers?