• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to timeout a task in ThreadPoolExecutor

 
Thiyagarajan Ramasamy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multi Threading Gurus,
I have to execute a set of runnable tasks in parallel and each of the task shouldn't execute more than 2 mins.

I was thinking of using ThreadPoolExecutor, but there is seems to be no way to interrupt / configure timeout for a task. I can only configure the timeout for the pool.

Is there any way to achieve this?

Thanks in advance.
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Check the following api: FutureTask#get(int, TimeUnit).

Hope it helps.


Regards,
Rok
 
abhay bansal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Correct me if I am wrong. A task when submitted to an executor and when the worker thread picks up the task even the executor has no control over the task then. It is al in the hands of the worker thread.

Thanks

Abhay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!