[concurrency-interest] Concurrent Serialization Pattern

Kevin Condon conivek at gmail.com
Thu Sep 14 14:46:14 EDT 2006


Hi Tom,

On 9/14/06, Thomas Hawtin <tackline at tackline.plus.com> wrote:
> In 1.6, java.util.Random (resetSeed method) uses sun.misc.Unsafe to poke
> it's final, (effectively) transient seed field. Not something I would
> generally recommend.

Agreed.  I'd much rather rely on the default serialization "magic" to
ensure that the final fields never publish anything other than the
deserialized field values.  JLS certainly discourages non-wizards from
exercising such magic.  :)

> If you don't have to worry about a serialisable base class, then it
> might be simpler just to introduce a non-serialisable, package private
> base class.

Ahh, that would be a clever way to avoid implementing the custom
serialization.  I've actually made it a habit to make serializable
state fields transient and doing the custom serialize/deserialize code
(based on the recommendations in Efffective Java), but I can see why
someone might not think the extra work required was worthwhile in
every case.

Kevin


More information about the Concurrency-interest mailing list