The Artima Developer Community
Sponsored Link

Java Answers Forum
Can threads commnicate?

1 reply on 1 page. Most recent reply: Mar 26, 2002 1:47 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Avin Sinanan

Posts: 28
Nickname: avin
Registered: Feb, 2002

Can threads commnicate? Posted: Mar 26, 2002 1:22 PM
Reply to this message Reply
Advertisement
Hello,
I know that threads allow events or actions to take place in parallel.
But if a method or some set of actions are being excuted in seperat threads can one one thread send another value to another thread.

That is,threads can be parallel but can they also be dependent on one another?

Can someone breif me on this please. Thanks a million.

yours respectfully Avin Sinanan


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Can threads commnicate? Posted: Mar 26, 2002 1:47 PM
Reply to this message Reply
Yes two threads can communicate. In fact, a thread is also a class and one class can communicate with another. Here is the simple case:
Thread1 t1 = new Thread1() ;
Thread1 t2 = new Thread2() ;
t1.setThread ( t2 ) ;
t2.setThread ( t1 ) ;

t1.start();
t2.start() ;

YOu will create an instance variable for Thread1 and Thread2. They will be of type Thread2 and Thread1 respectively. Your setThread method will store the references of each other. Now, suppose in thread 1 you need to get some value from thread2 , you can always call a method within thread1 on thread2 because you have stored the reference of thread2 inside thread1.

Thanks
Kishori

Flat View: This topic has 1 reply on 1 page
Topic: Can anyone tell me where I went wrong?? Previous Topic   Next Topic Topic: What is meant by an alias?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use