Consistent implementation of AsyncListenableTaskExecutor

Issue: SPR-11282
This commit is contained in:
Juergen Hoeller
2014-01-03 21:57:07 +01:00
parent 6a5a3c97ed
commit 640d8cb67f
10 changed files with 208 additions and 37 deletions

View File

@@ -20,7 +20,6 @@ import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import javax.naming.NamingException;
import commonj.work.Work;
@@ -31,11 +30,14 @@ import commonj.work.WorkManager;
import commonj.work.WorkRejectedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.TaskRejectedException;
import org.springframework.jndi.JndiLocatorSupport;
import org.springframework.scheduling.SchedulingException;
import org.springframework.scheduling.SchedulingTaskExecutor;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureTask;
/**
* TaskExecutor implementation that delegates to a CommonJ WorkManager,
@@ -61,7 +63,7 @@ import org.springframework.util.Assert;
* @since 2.0
*/
public class WorkManagerTaskExecutor extends JndiLocatorSupport
implements SchedulingTaskExecutor, WorkManager, InitializingBean {
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, WorkManager, InitializingBean {
private WorkManager workManager;
@@ -153,6 +155,20 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
return future;
}
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
execute(future);
return future;
}
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
ListenableFutureTask<T> future = new ListenableFutureTask<T>(task);
execute(future);
return future;
}
/**
* This task executor prefers short-lived work units.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,12 @@ import org.quartz.simpl.SimpleThreadPool;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.scheduling.SchedulingException;
import org.springframework.scheduling.SchedulingTaskExecutor;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureTask;
/**
* Subclass of Quartz's SimpleThreadPool that implements Spring's
@@ -45,7 +48,7 @@ import org.springframework.util.Assert;
* @see SchedulerFactoryBean#setTaskExecutor
*/
public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
implements SchedulingTaskExecutor, InitializingBean, DisposableBean {
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean {
private boolean waitForJobsToCompleteOnShutdown = false;
@@ -92,6 +95,20 @@ public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
return future;
}
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
execute(future);
return future;
}
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
ListenableFutureTask<T> future = new ListenableFutureTask<T>(task);
execute(future);
return future;
}
/**
* This task executor prefers short-lived work units.
*/