'futuretask get(long timeout, TimeUnit unit) ,The receiving time will be 10ms longer

long start = System.currentTimeMillis();

Future f = executor.submit(()-> {
    TimeUnit.MILLISECONDS.sleep(20);
    return "result";
});

try {
    f.get(18, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
    logger.info("inter");
} catch (ExecutionException e) {
    logger.info("execute");
} catch (TimeoutException e) {
    //will be print
    logger.info("future timeout={}", System.currentTimeMillis() - start);
}
long end = System.currentTimeMillis() - start;
// Why print 22-40ms
logger.info("future cast time={}", end);

//environment:window10,i7-6700(cpu),memory 16g //My question is: where does time go????



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source