Java Reference
In-Depth Information
@Autowired
private SyncTaskExecutor syncTaskExecutor;
@Autowired
private TaskExecutorAdapter taskExecutorAdapter;
/* No need, since the scheduling is already configured,
in the application context
@Resource(name = "timerTaskExecutorWithScheduledTimerTasks")
private TimerTaskExecutor timerTaskExecutorWithScheduledTimerTasks;
*/
@Resource(name = "timerTaskExecutorWithoutScheduledTimerTasks")
private TimerTaskExecutor timerTaskExecutorWithoutScheduledTimerTasks;
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private DemonstrationRunnable task;
public void submitJobs() {
syncTaskExecutor.execute(task);
taskExecutorAdapter.submit(task);
asyncTaskExecutor.submit(task);
timerTaskExecutorWithoutScheduledTimerTasks.submit(task);
/* will do 100 at a time,
then queue the rest, ie,
should take round 5 seconds total
*/
for (int i = 0; i < 500; i++)
threadPoolTaskExecutor.submit(task);
}
}
The application context demonstrates the creation of these various
TaskExecutor
implementations.
Most are so simple that you could create them manually. Only in one case (the
timerTaskExecutor
) do
you delegate to a factory bean:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:p="
http://www.springframework.org/schema/p"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="
http://www.springframework.org/schema/util"
xmlns:context="
http://www.springframework.org/schema/context"
xsi:schemaLocation="
Search WWH ::
Custom Search