Time limit on individual threads with ExecutorService

后端 未结 5 1141

I have an ExecutorService managing a number of Callables. The tasks that the Callables run are mostly black box transformations and number crunching. Under certain condition

5条回答
  •  旧时难觅i
    2020-12-09 05:38

    You could get a list of your corresponding Futures (that are created when you submit a Callable) together with its startup time.

    Another task could then check every minute if there are some task running for more than a defined time and if so, invoke cancel(true) in the Future. Done futures would be removed off the list.

提交回复
热议问题