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.14 by jsr166, Mon Feb 25 22:26:49 2013 UTC vs.
Revision 1.15 by jsr166, Wed Feb 27 16:55:04 2013 UTC

# Line 54 | Line 54 | public class ThreadLocalRandom extends R
54       * programs.
55       *
56       * Because this class is in a different package than class Thread,
57 <     * field access methods must use Unsafe to bypass access control
58 <     * rules.  The base functionality of Random methods is
59 <     * conveniently isolated in method next(bits), that just reads and
60 <     * writes the Thread field rather than its own field. However, to
61 <     * conform to the requirements of the Random constructor, during
62 <     * construction, the common static ThreadLocalRandom must maintain
63 <     * initialization and value fields, mainly for the sake of
64 <     * disabling user calls to setSeed while still allowing a call
65 <     * from constructor.  For serialization compatibility, these
66 <     * fields are left with the same declarations as used in the
67 <     * previous ThreadLocal-based version of this class, that used
68 <     * them differently. Note that serialization is completely
69 <     * unnecessary because there is only a static singleton. But these
70 <     * mechanics still ensure compatibility across versions.
57 >     * field access methods use Unsafe to bypass access control rules.
58 >     * The base functionality of Random methods is conveniently
59 >     * isolated in method next(bits), that just reads and writes the
60 >     * Thread field rather than its own field.  However, to conform to
61 >     * the requirements of the Random superclass constructor, the
62 >     * common static ThreadLocalRandom maintains an "initialized"
63 >     * field for the sake of rejecting user calls to setSeed while
64 >     * still allowing a call from constructor.  Note that
65 >     * serialization is completely unnecessary because there is only a
66 >     * static singleton.  But we generate a serial form containing
67 >     * "rnd" and "initialized" fields to ensure compatibility across
68 >     * versions.
69       *
70 <     * Per-instance initialization is similar to that in the no-arg
70 >     * Per-thread initialization is similar to that in the no-arg
71       * Random constructor, but we avoid correlation among not only
72       * initial seeds of those created in different threads, but also
73       * those created using class Random itself; while at the same time
# Line 156 | Line 154 | public class ThreadLocalRandom extends R
154       * @throws UnsupportedOperationException always
155       */
156      public void setSeed(long seed) {
157 <        if (initialized) // allow call from super() constructor
157 >        // only allow call from super() constructor
158 >        if (initialized)
159              throw new UnsupportedOperationException();
160      }
161  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines