Java ThreadLocalRandom 类的 setSeed() 方法抛出 UnsupportedOperationException。在此生成器中,不支持设置种子。此方法覆盖 Random 类中的 setSeed。
用法:
public void setSeed(long seed)
参数:
seed:这是初始种子
异常:
UnsupportedOperationException:此异常将始终抛出。
例子1
import java.util.concurrent.ThreadLocalRandom;
public class ThreadLocalRandomSetSeedExample1 {
public static void main(String args[])
{
final ThreadLocalRandom random = ThreadLocalRandom.current();
random.setSeed(15); //exception will come as seeding is not allowed in ThreadLocalRandom.
System.out.println("Seeded Thread Local Random Integer:" + random.nextInt());
}
}
输出:
Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.concurrent.ThreadLocalRandom.setSeed(Unknown Source) at tests.JavaDateSetTimeExample1.main(ThreadLocalRandomSetSeedExample1.java:8)
相关用法
- Java ThreadLocalRandom longs()用法及代码示例
- Java ThreadLocalRandom current()用法及代码示例
- Java ThreadLocalRandom ints()用法及代码示例
- Java ThreadLocalRandom nextLong()用法及代码示例
- Java ThreadLocalRandom nextDouble()用法及代码示例
- Java ThreadLocalRandom nextGaussian()用法及代码示例
- Java ThreadLocalRandom doubles()用法及代码示例
- Java ThreadLocalRandom nextInt()用法及代码示例
- Java Thread toString()用法及代码示例
- Java ThreadGroup enumerate()用法及代码示例
- Java ThreadGroup getMaxPriority()用法及代码示例
- Java ThreadGroup getParent()用法及代码示例
- Java Thread interrupted()用法及代码示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代码示例
- Java Thread suspend()用法及代码示例
- Java Thread destroy()用法及代码示例
- Java Thread holdLock()用法及代码示例
- Java Thread getContextClassLoader()用法及代码示例
- Java Thread setContextClassLoader()用法及代码示例
- Java ThreadGroup getName()用法及代码示例
注:本文由纯净天空筛选整理自 Java ThreadLocalRandom setSeed() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。