ability to get the progress on a Future object

前端 未结 3 1239
我寻月下人不归
我寻月下人不归 2021-02-05 14:20

With reference to the java.util.concurrent package and the Future interface I notice (unless I am mistaken) that the ability to start a lengthy tasks and be able to query on the

3条回答
  •  无人共我
    2021-02-05 14:54

    Obviously, the Future object would only be good for blocking and then receiving the result.

    The Runnable or Callable object that you submit would either have to know how to provide this progress (percentage complete, count of attempts, status (enum?) etc) and provide that as an API call to the object itself, or posted in some lookup resource (in memory map or database if necessary). For simplicity I tend to like the object itself, especially since you're going to most likely need a handle (id) to lookup the object or a reference to the object itself.

    This does mean that you have 3 threads operating. 1 for the actual work, 1 that is blocked while waiting for the result, and 1 that is a monitoring thread. The last one could be shared depending on your requirements.

提交回复
热议问题