added "Future submit(Runnable)" and "Future submit(Callable)" to AsyncTaskExecutor; SchedulingTaskExecutor interface extends AsyncTaskExecutor; added ExecutorServiceAdapter class as a standard wrapper for a Spring TaskExecutor; added ThreadPoolExecutorFactoryBean; reduced backport-concurrent support to TaskExecutor adapters

This commit is contained in:
Juergen Hoeller
2009-02-05 22:45:35 +00:00
parent 6cdc25d66a
commit 7e4fb09369
28 changed files with 940 additions and 1100 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -16,10 +16,8 @@
package org.springframework.scheduling.commonj;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.naming.NamingException;
import commonj.timers.Timer;
@@ -141,7 +139,7 @@ public class TimerManagerFactoryBean extends JndiLocatorSupport
if (this.timerManagerName == null) {
throw new IllegalArgumentException("Either 'timerManager' or 'timerManagerName' must be specified");
}
this.timerManager = (TimerManager) lookup(this.timerManagerName, TimerManager.class);
this.timerManager = lookup(this.timerManagerName, TimerManager.class);
}
if (this.scheduledTimerListeners != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -17,6 +17,9 @@
package org.springframework.scheduling.commonj;
import java.util.Collection;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.Callable;
import javax.naming.NamingException;
@@ -131,7 +134,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
if (this.workManagerName == null) {
throw new IllegalArgumentException("Either 'workManager' or 'workManagerName' must be specified");
}
this.workManager = (WorkManager) lookup(this.workManagerName, WorkManager.class);
this.workManager = lookup(this.workManagerName, WorkManager.class);
}
}
@@ -159,6 +162,22 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport
}
}
public void execute(Runnable task, long startTimeout) {
execute(task);
}
public Future<?> submit(Runnable task) {
FutureTask<Object> future = new FutureTask<Object>(task, null);
execute(future);
return future;
}
public <T> Future<T> submit(Callable<T> task) {
FutureTask<T> future = new FutureTask<T>(task);
execute(future);
return future;
}
/**
* This task executor prefers short-lived work units.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2009 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.
@@ -16,6 +16,10 @@
package org.springframework.scheduling.quartz;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import org.quartz.SchedulerConfigException;
import org.quartz.simpl.SimpleThreadPool;
@@ -27,11 +31,10 @@ import org.springframework.util.Assert;
/**
* Subclass of Quartz's SimpleThreadPool that implements Spring's
* TaskExecutor interface and listens to Spring lifecycle callbacks.
* {@link org.springframework.core.task.TaskExecutor} interface
* and listens to Spring lifecycle callbacks.
*
* <p>Can be used as a thread-pooling TaskExecutor backend, in particular
* on JDK <= 1.5 (where the JDK ThreadPoolExecutor isn't available yet).
* Can be shared between a Quartz Scheduler (specified as "taskExecutor")
* <p>Can be shared between a Quartz Scheduler (specified as "taskExecutor")
* and other TaskExecutor users, or even used completely independent of
* a Quartz Scheduler (as plain TaskExecutor backend).
*
@@ -68,6 +71,22 @@ public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
}
}
public void execute(Runnable task, long startTimeout) {
execute(task);
}
public Future<?> submit(Runnable task) {
FutureTask<Object> future = new FutureTask<Object>(task, null);
execute(future);
return future;
}
public <T> Future<T> submit(Callable<T> task) {
FutureTask<T> future = new FutureTask<T>(task);
execute(future);
return future;
}
/**
* This task executor prefers short-lived work units.
*/