343 |
|
private static final long serialVersionUID = -5851777807851030925L; |
344 |
|
|
345 |
|
/** |
346 |
+ |
* @serialField rnd long |
347 |
+ |
* seed for random computations |
348 |
+ |
* @serialField initialized boolean |
349 |
+ |
* always true |
350 |
+ |
*/ |
351 |
+ |
private static final ObjectStreamField[] serialPersistentFields = { |
352 |
+ |
new ObjectStreamField("rnd", long.class), |
353 |
+ |
new ObjectStreamField("initialized", boolean.class), |
354 |
+ |
}; |
355 |
+ |
|
356 |
+ |
/** |
357 |
+ |
* Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it). |
358 |
+ |
*/ |
359 |
+ |
private void writeObject(java.io.ObjectOutputStream out) |
360 |
+ |
throws java.io.IOException { |
361 |
+ |
|
362 |
+ |
java.io.ObjectOutputStream.PutField fields = out.putFields(); |
363 |
+ |
fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED)); |
364 |
+ |
fields.put("initialized", true); |
365 |
+ |
out.writeFields(); |
366 |
+ |
} |
367 |
+ |
|
368 |
+ |
/** |
369 |
|
* Returns the {@link #current() current} thread's {@code ThreadLocalRandom}. |
370 |
|
*/ |
371 |
|
private Object readResolve() { |