Re: Passing result from one thread to another thread at the end of execution

From: S Manohar (sgmanohar_at_hotmail.com)
Date: 02/17/04


Date: 16 Feb 2004 22:12:10 -0800

I don't know of any specific pattern, but the logical way would be to
create a single class that encapsulates the running of the thread AND
the result, e.g.

class abstract ThreadWithResult extends Thread {
 private boolean finished=false;
 private Object result=null;
 public Object getResult() throws IllegalStateException{
  if(finished)throw new IllegalStateException("Process incomplete");
  return result;
 }
 public void run(){
  ...
  result=...;
  finished=true;
 }
}

then
{
 ThreadWithResult t=new ThreadWithResult();
 t.start();
 t.join();
 Object r=t.getResult();
}

But there could be a more elegant way using synchronised
methods...?

"sayoyo" <dontwantspam@yahoo.com> wrote in message news:<k15Xb.20445$y07.617821@news20.bellglobal.com>...
> Hello:)
>
> I wish to know if there is some pattern design that allow passing the result
> of one executing thread(at the end of the execution) to another thread.
>
> And it is possible to pass data between two threads without having a shared
> variable? event-listener model will it works????
>
> Thanks you very much!!!!
>
> Sayoyo



Relevant Pages

  • Re: Annika
    ... striking and hit/or miss executing the missed approach and heading to the hold pattern. ...
    (rec.photo.equipment.35mm)
  • Re: How does a generator object refer to itself?
    ... Because we use this pattern for thousands of functions, ... we use a single class that creates an instance for each ... such generator. ... more lightweight than that. ...
    (comp.lang.python)
  • Re: Self restarting property of RTOS-How it works?
    ... >> After restarting will the task start executing from the starting ... >> the point where its terminated before restarting?). ... who feel obliged to be insulting even if the question was politely ... I think there is a pattern here. ...
    (comp.arch.embedded)