2
只恐的考慮,我有以下幾點:如何在Spring TaskExecutor中分配任務名稱並檢查它是否仍然存在?
public class MyRunnable implements Runnable {
public void run() {
//do something expensive
}
}
public class ThreadExecutor {
private TaskExecutor taskExecutor;
public ThreadExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
public void fireThread(){
taskExecutor.execute(new MyRunnable());
}
}
我的XML如下:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="queueCapacity" value="25" />
</bean>
<bean id="threadExecutor" class="com.vanilla.threads.controllers.ThreadExecutor">
<constructor-arg ref="taskExecutor" />
</bean>
在我的Spring MVC控制器
我開始任務:
@RequestMapping(value="/startTask.html", method=RequestMethod.GET)
public ModelAndView indexView(){
ModelAndView mv = new ModelAndView("index");
threadExecutor.fireThread();
return mv;
}
現在讓我們考慮我想創建另一個請求(@RequestMapping(value="/checkStatus.html"
),它會告訴我在以前的請求中啓動的任務是否已完成。
所以我的問題很簡單:
1)我可以在TaskExecutor的,如果是指定名稱的任務,我該怎麼辦呢?
2)如何檢查具有特定名稱的任務已完成?