使用版本4.5.27 我正在使用此代码将Throwable写入队列,然后将其读回。
public static void writeThrowableToQueue(){
final Throwable throwable;
try {
throw new RuntimeException("serialise");
}catch(Throwable e){
throwable = e;
}
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(file).build()) {
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(w -> {
w.getValueOut().int64(System.currentTimeMillis());
w.getValueOut().object(throwable);
});
}
try (ChronicleQueue queue = SingleChronicleQueueBuilder.binary(file).build()) {
final ExcerptTailer tailer = queue.createTailer();
tailer.readDocument(w -> {
ValueIn in = w.getValueIn();
long time = in.int64();
System.out.println(in.object());
});
}
}
写入工作正常,我可以在转储队列时看到异常。
但阅读引发了这个例外:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.clear(Collections.java:1074)
at net.openhft.chronicle.wire.WireMarshaller$CollectionFieldAccess.read(WireMarshaller.java:569)
at net.openhft.chronicle.wire.WireMarshaller.readMarshallable(WireMarshaller.java:143)
at net.openhft.chronicle.wire.Wires.readMarshallable(Wires.java:253)
at net.openhft.chronicle.wire.SerializationStrategies$5.readUsing(SerializationStrategies.java:121)
at net.openhft.chronicle.wire.BinaryWire$BinaryValueIn.marshallable(BinaryWire.java:2897)
at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:482)
at net.openhft.chronicle.wire.BinaryWire$BinaryValueIn.objectWithInferredType(BinaryWire.java:3158)
at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:435)
at queue.QueuePlayGround.lambda$writeThrowableToQueue$1(QueuePlayGround.java:44)
at net.openhft.chronicle.queue.impl.single.SingleChronicleQueueExcerpts$StoreTailer.readDocument(SingleChronicleQueueExcerpts.java:805)
at queue.QueuePlayGround.writeThrowableToQueue(QueuePlayGround.java:41)
at queue.QueuePlayGround.main(QueuePlayGround.java:20)
我尝试过使用其他物体(Marshallables),这样可以正常使用。
非常感谢您的帮助