Is it possible to call a method in java at specific time? For example of I have a piece of code like this:
class Test{
public static void main(String ar
You can use a ScheduledExecutorService, which is "a more versatile replacement for the Timer/TimerTask combination" (according to Timer's javadoc):
long delay = ChronoUnit.MILLIS.between(LocalTime.now(), LocalTime.of(13, 5, 45));
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.schedule(task, delay, TimeUnit.MILLISECONDS);