Hi Sim,
Agreed, however we still need to be able to provide a way to ensure some
tasks are run first there are dependencies between tasks, order sequence
etc, Chris put it most eloquently.
The big feature that TaskManager has that Java 1.5 lacks is the ability
to reorder the tasks by asking each task if it wants to be before the
others (Task.runAfter()). That could be refactored into a custom
BlockingQueue implementation, I suppose.
Chris
TaskManager (from recollection) returns any tasks that aren't ready to
run to the beginning of the queue. This wouldn't be acceptable with a
BlockingQueue when max threads has been reached.
Instead, I've created a class, DependantTask extends FutureTask, and an
interface called PriorityHandler, which the DependantTask expects in its
constructor.
When a DependantTask is run(), it first asks the PriorityHandler if
anything else should be run first, passing itself in as the argument.
The Runnable contained within the DependantTask can be revealed to a
PriorityHandler implementation, all the tasks on a BlockingQueue can be
observed, so the PriorityHandler implementation can use several
mechanisms in its determination.
The RunnableFuture's returned to DependantTask, by the PriorityHander
are run first, these may also be running in concurrent threads, however
this is acceptable as it will reduce the number of tasks run by the
DependantTask's thread.
Have a look on SVN, under org.apache.river.imp.util.* I'm not 100%
happy with it, perhaps you can improve it.
Cheers,
Peter.
Sim IJskes - QCG wrote:
On 06/17/2010 03:26 PM, Sim IJskes - QCG wrote:
So this would be an implementation that will mimmick the old behaviour?
ThreadFactory tf = new DaemonThreadFactory();
execSvc = new ThreadPoolExecutor(0, maxThreads, 15L, TimeUnit.MINUTES,
new LinkedBlockingQueue<Runnable>(1), tf, new AbortPolicy() );
execSvc.allowCoreThreadTimeOut(true);
maxThreads is the limit on the number of threads.
And a possible improvement would be:
tpe = new ThreadPoolExecutor(maxThreads, maxThreads, 15,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), tf, new
AbortPolicy() );
tpe.allowCoreThreadTimeOut(true);
Gr. Sim