ソースを参照

使用 ThreadLocalRandom 代替 Random

James 5 年 前
コミット
afa707abff

+ 2 - 3
src/main/java/com/jfinal/template/ext/directive/RandomDirective.java

@@ -17,6 +17,7 @@
 package com.jfinal.template.ext.directive;
 
 import java.io.IOException;
+import java.util.concurrent.ThreadLocalRandom;
 import com.jfinal.template.Directive;
 import com.jfinal.template.Env;
 import com.jfinal.template.TemplateException;
@@ -28,11 +29,9 @@ import com.jfinal.template.stat.Scope;
  */
 public class RandomDirective extends Directive {
 	
-	private java.util.Random random = new java.util.Random();
-	
 	public void exec(Env env, Scope scope, Writer writer) {
 		try {
-			writer.write(random.nextInt());
+			writer.write(ThreadLocalRandom.current().nextInt());
 		} catch (IOException e) {
 			throw new TemplateException(e.getMessage(), location, e);
 		}