Thread safe unmarshaller and marshaller

406 views
Skip to first unread message

dav...@gmail.com

unread,
May 4, 2013, 4:30:54 PM5/4/13
to bea...@googlegroups.com
Hi, Kevin

I've been using beanio in my project. It's better to have marshaller/unmarshaller to process multiple records by one instance instead of having one instance per record.

In my project, I use a cache now to store streamFactory based on different stream name, and create an unmarshaller in every thread call. Is there any better way to allow unmarshaller and marshaller support multi-threading processes, in another word, share the same marshaller/unmarshaller for different fixed length records.

Please advise. If beanio is not thread-safe now, are you planning to include it in the future release?

Thanks
- Lei

Kevin

unread,
May 6, 2013, 1:40:38 PM5/6/13
to bea...@googlegroups.com
Hi Lei,

As long as you are sharing the StreamFactory instance across threads, I wouldn't worry too much about creating a new Unmarshaller instance for each record.  The code is optimized to minimize object instantiation when a new Un/marshallers is created.  In my limited benchmarking, I saw about 500ms of overhead for creating 1 million unmarshallers.  If that is too high for your needs, you could explore using ThreadLocal variables (which have their own performance drawbacks) or adding an Unmarshaller to the class attributes of your Thread.

An un/marshaller will never be thread-safe because they are stateful for enforcing record grouping and ordering rules.  You could synchronize all access to one, but that would probably defeat the purpose of multi-threading.

Thanks,
Kevin

dav...@gmail.com

unread,
May 6, 2013, 10:19:32 PM5/6/13
to bea...@googlegroups.com
Kevin, it's good to know some real performance data. 500ms delay per 1 million un/marshallers is really nothing at all.

Thanks a lot.
- Lei
Reply all
Reply to author
Forward
0 new messages