Creating Scheduled Tasks

Report a typo

Complete the code to schedule the TimerTask task to run exactly once at the execTime:

public class Main {
    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerTask task = new TimerCode();

        LocalDateTime timeToExecute = LocalDateTime.now().plusSeconds(2);
        Date execTime = Date.from(timeToExecute.atZone(ZoneId.systemDefault()).toInstant());
        _________________
    }
}
Enter a short text
___

Create a free account to access the full topic