Multiple threads - multiple ExcerptAppender

120 views
Skip to first unread message

Vijay Veeraraghavan

unread,
May 29, 2014, 10:33:01 AM5/29/14
to java-ch...@googlegroups.com
Can there be many ExcerptAppender created from one Chronicle? I'm now experimenting with VanillaChronicle in a web environment. I initialize the Chronicle in the init and create ExcerptAppender. The doPost uses the ExcerptAppender instance of this Servlet and writes all the request parameter and its values to the index using the appender. How should this be approached? 

In a multi-threaded environment, when I create two threads (started with 5 seconds delay) who have ExcerptAppender created from a single chronicle. I get 
Exception in thread "writer1" java.lang.NullPointerException
at net.openhft.chronicle.VanillaChronicle$VanillaAppender.finish(VanillaChronicle.java:596)
at mn.WriterThread.run(VanillaTest.java:109)
at java.lang.Thread.run(Thread.java:744)
But when I create the VanillaChronicle, say in /tmp/traffic-data/index, in the thread, I get a smooth flow. The reader reads all the data written by both the threads. I couldn't find good docs on this. Is this a right approach to have multiple chronicles on same directory read by reader(s)?
thanks
--V

Peter Lawrey

unread,
May 29, 2014, 11:41:58 AM5/29/14
to java-ch...@googlegroups.com
You can have one appender per thread.  A simple way to do this is to call createAppender() in each thread as it will cache the appender for that thread.


--
You received this message because you are subscribed to the Google Groups "Java Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Veeraraghavan

unread,
May 30, 2014, 1:15:15 AM5/30/14
to java-ch...@googlegroups.com
That was brilliant Peter. Last night I was going through the VanillaChronicle code and saw it uses ThreadLocal. :-)
So, does it mean, I will call createAppender() on doPost or doGet, in case of a Servlet?
regards
--V

Vijay Veeraraghavan

unread,
May 30, 2014, 2:38:02 AM5/30/14
to java-ch...@googlegroups.com
Peter
I got this error when I was testing the VanillaChronicle that I wish to put it in a multi-threaded environment. I create 2 threads (WriterThread) to which I pass the chronicle instance I create in the main thread (VanillaTest). I create a 1 reader thread (ReaderThread), that too takes the same chronicle instance, to read all those written by the writer(s). The codes attached

Exception in thread "writer1" java.lang.NullPointerException
at net.openhft.chronicle.VanillaChronicle$VanillaAppender.finish(VanillaChronicle.java:533)
at mn.WriterThread.run(WriterThread.java:38)


regards
--V
ReaderThread.java
VanillaTest.java
WriterThread.java

Peter Lawrey

unread,
May 30, 2014, 3:38:57 AM5/30/14
to java-ch...@googlegroups.com

Yes you can do that. There is a slight overhead in doing this but it should be sub microsecond.

Vijay Veeraraghavan

unread,
May 30, 2014, 5:56:03 AM5/30/14
to java-ch...@googlegroups.com
Can you please run my codes and reply if you get any errors? is that a bug in the chronicle or the way I implemented the chronicle?
thanks
-V

Peter Lawrey

unread,
May 30, 2014, 7:25:16 AM5/30/14
to java-ch...@googlegroups.com
It could be both, however our tests which do this all pass.
Reply all
Reply to author
Forward
0 new messages