[concurrency-interest] Re: Help, how to design a pool of threads
andrejnavodnik at yahoo.com
Sat Nov 5 11:52:20 EST 2005
thank you very much for your quick response.
I have already studied the example program you have
suggested but if I understand it correctly the threads
in the pool are canceled/stopped AFTER the final
result is found/prepared. Actually, I'd like to have a
pool where threads could be canceled/stopped BEFORE
one the threads prepares final result.
Suppose that the algorithm is testing different
variants for the next step and that this phase must
also produce some data for the next step. Suppose
also, that during this step, let's say approximately
about at 1/3 to 1/5 of the total work, it must decide
whether the input data would produce useful results or
not. If the input data could not produce useful result
then the algorithm should try with another parameters.
But in case that the algorithm could predict that the
result could be useful then I'd like to stop other
threads because they are using valuable resources
(CPU) and I'd like to give priority only to the thread
that is one the right path. So, I'd like to test some
kind of an intermediate condition and AFTER this
condition there would be only one working thread in
the pool which would produce result. I'd like to
implement a strategy where only an owner of the right
token is given the right to run in the final.
--- Doug Lea <dl at cs.oswego.edu> wrote:
> Andrej Navodnik wrote:
> > My questions are:
> > - how should I design my application so that the
> > in the pool would be canceled/stopped after the
> > optimal element is found except for the task
> > that has found that optimal element - I wouldn't
> > like to see the message Task is still doing
> > things because it's actually using resources that
> > should be used fior preparing the final result;
> > - should I concern about this problem or not?
> > - are there any other constructs that I could
> > use and achieve the same result?
> You might find the second code example in the
> javadoc helpful. See
Yahoo! Mail - PC Magazine Editors' Choice 2005
More information about the Concurrency-interest