Don’t try to serialize large ConcurrentSkipListMaps

Today I learned the hard way that Java can’t serialize large ConcurrentSkipListMaps (and probably ConcurrentSkipListSets too). The issue is that there doesn’t seem to be any custom serialization implementation for this class, and the default serialization mechanism ends up joyfully recursing its way along the map’s internal object graph – eventually causing a StackOverflowException. Nice.

The root issue here is, of course, Java’s default serialization mechanism, which really shouldn’t operate recursively like this. Turns out that this has been a known issue for an embarrassing length of time (see this 9 year old bug report).

The workaround is to subclass ConcurrentSkipListMap providing a more efficient serialization mechanism – actually its not too hard, the code is here. Its public domain, so enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>