Programar un java.util.concurrent.Callable a través de Spring significa

La primavera org.springframework.scheduling.TaskScheduler is different from the JDK java.util.concurrent.ScheduledExecutorService in the way that it does not allow scheduling a java.util.concurrent.Callable with a fixed delay (it can just schedule java.lang.Runnables).

Is there a Spring-based alternative to the ScheduledExecutorService available (that is automatically shut down on context destruction) that supports scheduling Callables?

preguntado el 08 de noviembre de 11 a las 10:11

It does not allow returning a result. -

you're right, you can submit a Callable to a ThreadPoolTaskScheduler, but you can only schedule a Runnable. Why can't you use ScheduledExecutorService directly? -

I'd like to have the thread pool shut down automatically when the Spring context is destroyed. My current workaround for this is to use a DisposableBean for this task, but it would be nice to have this as part of the framework. -

went to lunch and @alf beat me to it :) -

1 Respuestas

If the only thing you need is shutdown, use destroy-method:

<bean id="threadPool" class="java.util.concurrent.Executors" 
    <constructor-arg type="int" value="6"/>

Works just fine for us.

PS. You may need to use factory-method="newScheduledThreadPool" en vez.

respondido 09 nov., 11:21

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.