|
8 | 8 | import java.security.MessageDigest; |
9 | 9 | import java.util.Map; |
10 | 10 | import java.util.Properties; |
| 11 | +import java.util.concurrent.Executors; |
| 12 | +import java.util.concurrent.ScheduledExecutorService; |
| 13 | +import java.util.concurrent.ThreadFactory; |
| 14 | +import java.util.concurrent.TimeUnit; |
11 | 15 | import com.googlecode.aviator.runtime.RuntimeUtils; |
12 | 16 | import com.googlecode.aviator.runtime.type.AviatorBigInt; |
13 | 17 | import com.googlecode.aviator.runtime.type.AviatorDecimal; |
|
22 | 26 | * |
23 | 27 | */ |
24 | 28 | public class Utils { |
25 | | - private static final String CURRENT_VERSION = "5.0.0"; |
| 29 | + private static final String CURRENT_VERSION = "5.4.2"; |
26 | 30 |
|
| 31 | + private static final int TICK_INTERVAL_MS = |
| 32 | + Integer.parseInt(System.getProperty("aviator.tick.interval_ms", "1")); |
27 | 33 |
|
28 | 34 | private Utils() { |
29 | 35 |
|
30 | 36 | } |
31 | 37 |
|
| 38 | + private static class StaticHolder { |
| 39 | + static ScheduledExecutorService tickService = |
| 40 | + Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { |
| 41 | + |
| 42 | + @Override |
| 43 | + public Thread newThread(Runnable r) { |
| 44 | + Thread thread = new Thread(r); |
| 45 | + thread.setDaemon(true); |
| 46 | + thread.setName("aviatorscript-tick-thread"); |
| 47 | + return thread; |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + static volatile long nowNs = System.nanoTime(); |
| 52 | + |
| 53 | + static { |
| 54 | + tickService.scheduleAtFixedRate(new Runnable() { |
| 55 | + |
| 56 | + @Override |
| 57 | + public void run() { |
| 58 | + nowNs = System.nanoTime(); |
| 59 | + } |
| 60 | + }, 0, TICK_INTERVAL_MS, TimeUnit.MILLISECONDS); |
| 61 | + } |
| 62 | + } |
| 63 | + |
32 | 64 | public static long currentTimeNanos() { |
33 | | - return System.nanoTime(); |
| 65 | + return StaticHolder.nowNs; |
34 | 66 | } |
35 | 67 |
|
36 | 68 | private static final ThreadLocal<MessageDigest> MESSAGE_DIGEST_LOCAL = |
|
0 commit comments