-
public class CurrentTimeMillis {
private volatile long now;
private CurrentTimeMillis() {
this.now = System.currentTimeMillis();
this.scheduleTick();
}
private void scheduleTick() {
(new ScheduledThreadPoolExecutor(1, (runnable) -> {
Thread thread = new Thread(runnable, "tool-current-time-millis");
thread.setDaemon(true);
return thread;
})).scheduleAtFixedRate(() -> {
this.now = System.currentTimeMillis();
}, 1L, 1L, TimeUnit.MILLISECONDS);
}
public static long now() {
return getInstance().now;
}
private static CurrentTimeMillis getInstance() {
return CurrentTimeMillis.SingletonHolder.INSTANCE;
}
private static class SingletonHolder {
private static final CurrentTimeMillis INSTANCE = new CurrentTimeMillis();
private SingletonHolder() {
}
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
/cc @zakkak (native-image) |
Beta Was this translation helpful? Give feedback.
-
Hi @seepine, this is not Quarkus specific. You can replicate it by adding a
What happes here is that GraalVM's native-image initializes the class Typically this is solved by registering |
Beta Was this translation helpful? Give feedback.
-
@zakkak Thanks, can i replace with this ? and public class CurrentTime {
public static long startNanoTime = System.currentTimeMillis() * 1_000_000;
public static long startNano = System.nanoTime();
/**
*
* @return nano
*/
public static long nano() {
return startNanoTime + System.nanoTime() - startNano;
}
/**
*
* @return micro
*/
public static long micro() {
return nano() / 1_000;
}
/**
*
* @return milli
*/
public static long milli() {
return nano() / 1_000_000;
}
/**
*
* @return second
*/
public static long second() {
return nano() / 1_000_000_000;
}
public static LocalDateTime now() {
Instant instant = Instant.ofEpochSecond(0, nano());
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}
} |
Beta Was this translation helpful? Give feedback.
@zakkak Thanks, it can work now that i modified it like this.
Maybe the reason
But this is my guess, after all, the native docker image can be work in my local.
Anyway, at least it can …