[concurrency-interest] Re: Help, how to design a pool of threads

Andrej Navodnik andrejnavodnik at yahoo.com
Sat Nov 5 11:52:20 EST 2005


Hi Doug,

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. 

Best regards,
Andrei


--- Doug Lea <dl at cs.oswego.edu> wrote:

> Andrej Navodnik wrote:
> > 
> > My questions are:
> > - how should I design my application so that the
> tasks
> > 
> > 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
> useless
> > 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
> ExecutorCompletionService
> javadoc helpful. See
> 
>
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html
> 
> -Doug
> 
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the Concurrency-interest mailing list