Chào các bạn.

Câu hỏi hôm nay như sau:

Problem

Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds.

Code

public class Main {
    public static void main(String[] args) {
        solution(() -> System.out.println("Hello World"), 10000);
    }

    public static void solution(Command command, int n) {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                command.execute();
            }
        }, n);

    }

    interface Command {
        void execute();
    }

}

Source code

https://github.com/tubean/dailycode/tree/master/src/day9

Reference

https://codereview.stackexchange.com/questions/214538/implement-a-job-scheduler-which-takes-in-a-function-f-and-an-integer-n-and-call