狗家店面 新题!

毕业之后半年左右,前段时间被Google HR在linkedin上联系,遂电面了一波Google!应该是被算成newgrad面试官是Kaggle组的,给我出了一道非常好的题。题真的非常好,奈何我做不出来。在此po出来希望能跟大家讨论讨论
直接上题!
Given the MySystem class

class MySystem {
    ...
    
    /**
     * Waits durationMillis milliseconds then runs the callback.
     *
     * Only one timer can be pending at one time.  If called again before the
     * duration expires, the original timer is overwritten without running
     * callback.
    */
    static void setTimer(long durationMillis, Runnable callback);

    /** Returns the current time in milliseconds since system boot. */
    static long getCurrentTimeMillis();
    
    ...
}

Please implement support for multiple timers:

/**
 * Waits durationMillis milliseconds then runs the callback.
 *
 * Supports multiple concurrent timers -- calling add_timer will not break
 * any previously started timers.
 */
void addTimer(long durationMillis, Runnable callback);

这个addTimer在MySystem里面。用法如下:
MySystem sys = new MySystem();
sys.addTimer(100, runnable1);
sleep(50)
sys.addTimer(100, runable2);

一个思路,不一定对
可不可以把(execution_time,callback)存到一个priority queue里,然后每次在setTimer的callback里call下一次的setTimer?
顺便

一个map存对应的callback,把callback注册到executorservice内,设一个delay,然后如果到时间了,自己运行,自己清空map,如果新的加进来了,取消上一个重新注册。不知道是不是这个意思。

LZ應該是java選手吧?
java好像有runnerble這個class