Executor Service - timeout of thread

后端 未结 3 1131
Happy的楠姐
Happy的楠姐 2021-02-04 19:56

While I was exploring ExecutorService, I encountered a method Future.get() which accepts the timeout.

The Java doc of this method

3条回答
  •  猫巷女王i
    2021-02-04 20:33

    my callable will interrupt after the specified time(timeout) has passed

    The above statement is wrong, Usually Future.get is blocking. Specifying the timeout allows you to use it in a non blocking manner.

    This is useful for instance in time critical applications, if you need a result within let's say 2 seconds and receiving after that means you can't do anything with that.

提交回复
热议问题