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

S

sayoyo

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
 
X

xarax

sayoyo said:
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.

Generally, it is a volatile variable somewhere that
will indicate that the result in another volatile
variable is ready. When the receiving thread has
nothing else to do, it can call workerThread.join() to
wait for the worker thread to finish its work. When
join() returns, the worker thread is dead. Then check
the flag variable to see whether the result was correctly
stored in the other variable. Read the JavaDoc on the
details of Thread.join().

If the worker thread stays around to handle more
work requests, then you have to go the other way
by designing the receiver thread to wait() on a signalling
object. When the worker thread has finished its processing
on the current request, it calls signalObject.notify() to
awaken the receiver thread that is waiting for the result.
Read the JavaDoc on the details of Object.wait() and notify().
And it is possible to pass data between two threads without having a shared
variable? event-listener model will it works????

EventListener is not a multi-threading API.
 
E

ExGuardianReader

sayoyo said:
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!!!!

Take a look at the new 1.5 SDK. The new java.util.concurrent package
contains a lot of classes which implement almost any concurrent software
pattern you need to use.
 
S

sayoyo

Thanks you very much for all the replys :)!!!!!!

ExGuardianReader said:
Take a look at the new 1.5 SDK. The new java.util.concurrent package
contains a lot of classes which implement almost any concurrent software
pattern you need to use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top