views:

472

answers:

1

Is it possible to use Java FutureTask with a Spring TaskExecutor to get a Future object?

I'm looking for a TaskExecutor that implements the Java ExecutorService interface, in particular the submit() method. Looking through the Spring Javadocs doesn't reveal any classes like this. Is there some alternate method to handle futures through Spring TaskExecutors that I am unaware of?

If it is possible, could you also include an example?

+2  A: 

Spring 3 has added submit methods with support for Future objects to AsyncTaskExecutor. Until then if you want access to Future objects I think you will need to get the underlying JDK executor (e.g. using getThreadPoolExecutor) and submit tasks directly on that.

Mark
Thanks Mark. Any caveats when using getThreadPoolExecutor?
James McMahon
Not that I know of as the Spring class simply passes its calls onto the underlying executor.
Mark
Strange they didn't expose some methods until Spring 3.0.
James McMahon