8006409: ThreadLocalRandom should dropping padding fields from its serialized form
Martin Buchholz
martinrb at google.com
Mon Feb 25 22:25:52 UTC 2013
Perhaps slightly better is this variant, which adds doc for the
@serialField's.
/**
* @serialField rnd long
* seed for random computations
* @serialField initialized boolean
* always true
*/
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("rnd", long.class),
new ObjectStreamField("initialized", boolean.class),
};
/**
* Saves the {@code ThreadLocalRandom} to a stream (that is, serializes
it).
*/
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException {
java.io.ObjectOutputStream.PutField fields = out.putFields();
fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED));
fields.put("initialized", true);
out.writeFields();
}
On Mon, Feb 25, 2013 at 2:13 PM, Martin Buchholz <martinrb at google.com>wrote:
> Me too!
>
>
More information about the core-libs-dev
mailing list