ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ThreadLocalRandom.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ThreadLocalRandom.java (file contents):
Revision 1.8 by jsr166, Fri Jan 11 05:38:42 2013 UTC vs.
Revision 1.9 by dl, Wed Jan 16 15:04:04 2013 UTC

# Line 6 | Line 6
6  
7   package java.util.concurrent;
8  
9 + import java.io.ObjectStreamField;
10   import java.util.Random;
11   import java.util.concurrent.atomic.AtomicInteger;
12   import java.util.concurrent.atomic.AtomicLong;
# Line 103 | Line 104 | public class ThreadLocalRandom extends R
104          new ThreadLocal<Double>();
105  
106      /*
107 <     * Fields used only during singleton initialization
107 >     * Field used only during singleton initialization
108       */
108    private long rnd;    // superclass random value
109      boolean initialized; // true when constructor completes
110  
111      /** Constructor used only for static singleton */
# Line 293 | Line 293 | public class ThreadLocalRandom extends R
293       * main ThreadLocalRandom if we were to use it.
294       *
295       * Note: Because of package-protection issues, versions of some
296 <     * of these methods also appear in some subpackage classes.
296 >     * these methods also appear in some subpackage classes.
297       */
298  
299      /**
# Line 334 | Line 334 | public class ThreadLocalRandom extends R
334          return r;
335      }
336  
337 +    // Serialization support, maintains original persistent form.
338 +
339      private static final long serialVersionUID = -5851777807851030925L;
340  
341 +    /**
342 +     * @serialField rnd long
343 +     * @serialField initialized boolean
344 +     * @serialField pad0 long
345 +     * @serialField pad1 long
346 +     * @serialField pad2 long
347 +     * @serialField pad3 long
348 +     * @serialField pad4 long
349 +     * @serialField pad5 long
350 +     * @serialField pad6 long
351 +     * @serialField pad7 long
352 +     */
353 +    private static final ObjectStreamField[] serialPersistentFields = {
354 +            new ObjectStreamField("rnd", long.class),
355 +            new ObjectStreamField("initialized", boolean.class),
356 +            new ObjectStreamField("pad0", long.class),
357 +            new ObjectStreamField("pad1", long.class),
358 +            new ObjectStreamField("pad2", long.class),
359 +            new ObjectStreamField("pad3", long.class),
360 +            new ObjectStreamField("pad4", long.class),
361 +            new ObjectStreamField("pad5", long.class),
362 +            new ObjectStreamField("pad6", long.class),
363 +            new ObjectStreamField("pad7", long.class) };
364 +
365 +    /**
366 +     * Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it).
367 +     */
368 +    private void writeObject(java.io.ObjectOutputStream out)
369 +        throws java.io.IOException {
370 +
371 +        java.io.ObjectOutputStream.PutField fields = out.putFields();
372 +        fields.put("rnd", 0L);
373 +        fields.put("initialized", true);
374 +        fields.put("pad0", 0L);
375 +        fields.put("pad1", 0L);
376 +        fields.put("pad2", 0L);
377 +        fields.put("pad3", 0L);
378 +        fields.put("pad4", 0L);
379 +        fields.put("pad5", 0L);
380 +        fields.put("pad6", 0L);
381 +        fields.put("pad7", 0L);
382 +        out.writeFields();
383 +    }
384 +
385 +    /**
386 +     * Returns the {@link #current() current} thread's {@code ThreadLocalRandom}.
387 +     */
388 +    private Object readResolve() {
389 +        return current();
390 +    }
391 +
392      // Unsafe mechanics
393      private static final sun.misc.Unsafe UNSAFE;
394      private static final long SEED;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines