Hi Greg.  Answers in line.

On 27 July 2011 18:37, Greg Brown <gk_br...@verizon.net> wrote:
>> I wasted too much time yesterday realizing that TaskGroup &
>> TaskSequence don't use the java.util.concurrent.ExecutorService that
>> might be passed to their constructors.
>
> If I understand the issue, I think you mean that these classes are not 
> guaranteed to execute their subtasks using the same ExecutorService that they 
> were given. Is that correct?

No it is a little more than that.  When a standard Task is created, it
either uses a default ExecutorService or the one provided to it.  This
cannot be changed later.

TaskGroup & TaskSequence extend Task and also accept an
ExecutorService, but this is never used (no call to
getExecutorService())

In their execute() methods, they both just iterate over the added
Tasks and call
((Task<Object>)task).execute(taskListener);
on each Tasks.

This will execute each Task using its internal ExecutorService, and
not the one supplied to the TaskGroup/TaskSequence.


>> I can't really work out the intent of the classes from the javadocs or
>> decide if they are still required (at least in their current forms).
>> Neither is used within Pivot itself.
>
> They are just utility classes for executing a set of tasks in sequence or in 
> parallel. Even though they are not used by the platform, I believe there is a 
> unit test for these classes.

There is a 'unit test', but it has no assertions, comments or coverage
of the constructors that take an ExecutorService, so doesn't clarify
anything.


>> Are they supposed to use a provided ExecutorService or is the
>> constructor just a copy & paste mistake?
>
> Not sure what you mean by this. TaskGroup(ExecutorService) and 
> TaskSequence(ExecutorService) do appear to pass the given executor service to 
> the base class. Am I missing something?

They pass it to the base class, but it is never accessed.  That is why
I am not sure of the intent.  Is the supplied ExecutorService supposed
to be used?


>> If the former, then it is probably worth adding a
>> setExecutorService(ExecutorService) method to
>> org.apache.pivot.util.concurrent.Task so that TaskGroup & TaskSequence
>> can control the ExecutorService to use when running the individual
>> tasks.
>
> Is the question whether we should enforce that subtasks are executed by the 
> same executor service as their parent?
Yes, that is what I thought would happen if I supply an ExecutorService.

> If so, why might we want to do that?
I thought that I would be able to do something like this to execute an
arbitrary group of Tasks in parallel, but limited to only 3 being
started at any given moment.

TaskGroup taskGroup = new TaskGroup(Executors.newFixedThreadPool(3));

Chris

Reply via email to