4
votes

I'm using openejb and asynchronous EJBs. I have a lot of Futures and would like to know if one on the futures takes too much time (so i can trace it and finally cancel it). The problem is that to know since how long the future si running, I need to know when it starts. The Future interface let me know if a Future is finished or cancelled, but if it's not, I can't know if it's running or waiting for a thread in the pool. Is it possible to get the Future status (Running/Not started)?

Thanks

1
Doesn't seem as if Future allows this. You could always have the task add itself to a collection, then check the collection to see which tasks are running. - Dioxin
Yes but I'd like to have a generic solution - jaudo
It seems this flag-like system is the only way to easily achieve this behavior. Your next option would be extending upon the Future interface to add the flag to each future. But this would require you to mess around with whichever executor you are currently using, in order to have the executor pass you an instance of your Future implementation containing the flag - Dioxin
Could you show the code where the tasks are created and the Future objects are being used? I'll attempt write an answer that fits your needs - Dioxin

1 Answers

-1
votes

I believe your intent is 1) Get the return value from submitted task using Future 2) If its taking too long , cancel it.

If this is correct - then why not use get with specifying timeout value.