By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <do**********@yahoo.com> wrote in message news:<k1********************@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

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.