< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/share/test/LocalRandom.java

Print this page

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 package nsk.share.test;
 25 
 26 import java.util.Random;
 27 import jdk.test.lib.Utils;
 28 import nsk.share.TestFailure;
 29 
 30 /**
 31  * Utility class which encapsulates all useful static methods.
 32  */
 33 public class LocalRandom {
 34     static {
 35         // ensure seed got printed out
 36         Utils.getRandomInstance();

 37     }
 38     private final static ThreadLocal<Random> random = new ThreadLocal<>() {
 39         protected Random initialValue() {
 40             // each thread gets its own seed independendly on the order they
 41             // use LocalRandom, yet it depends on the order threads are created.
 42             // main thread uses original seed
 43             return new Random(Utils.SEED ^ (Thread.currentThread().getId() - 1));
 44         }
 45     };
 46     private static int minPauseTime = 3000;
 47     private static int maxPauseTime = 5000;
 48     private static int maxRandomCount = 65536;
 49 
 50 
 51     /*
 52      * Initializes a thread-local instance to ensure that there is enough memory.
 53      * Useful for tests that exhaust memory.
 54      */
 55     public static void init() {
 56         random.get();

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 package nsk.share.test;
 25 
 26 import java.util.Random;
 27 import jdk.test.lib.Utils;
 28 import nsk.share.TestFailure;
 29 
 30 /**
 31  * Utility class which encapsulates all useful static methods.
 32  */
 33 public class LocalRandom {
 34     static {
 35         // ensure seed got printed out
 36         // TODO re-enalbe when monitor doesn't require to pin thread
 37         // Utils.getRandomInstance();
 38     }
 39     private final static ThreadLocal<Random> random = new ThreadLocal<>() {
 40         protected Random initialValue() {
 41             // each thread gets its own seed independendly on the order they
 42             // use LocalRandom, yet it depends on the order threads are created.
 43             // main thread uses original seed
 44             return new Random(Utils.SEED ^ (Thread.currentThread().getId() - 1));
 45         }
 46     };
 47     private static int minPauseTime = 3000;
 48     private static int maxPauseTime = 5000;
 49     private static int maxRandomCount = 65536;
 50 
 51 
 52     /*
 53      * Initializes a thread-local instance to ensure that there is enough memory.
 54      * Useful for tests that exhaust memory.
 55      */
 56     public static void init() {
 57         random.get();
< prev index next >