File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes How to timeout a task in ThreadPoolExecutor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to timeout a task in ThreadPoolExecutor" Watch "How to timeout a task in ThreadPoolExecutor" New topic
Author

How to timeout a task in ThreadPoolExecutor

Thiyagarajan Ramasamy
Greenhorn

Joined: Jan 15, 2010
Posts: 1
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

Joined: Nov 03, 2009
Posts: 101
Hi,

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

Hope it helps.


Regards,
Rok


SCJP, SCWCD
abhay bansal
Greenhorn

Joined: Nov 26, 2009
Posts: 8
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to timeout a task in ThreadPoolExecutor
 
Similar Threads
cancel tasks after a certain time
ThreadPoolExecutor restart
running a fixed number of threads all the time
Better than ThreadPoolExecutor
execute vs submit ( ThreadPoolExecutor)