|
Re: Can threads commnicate?
|
Posted: Mar 26, 2002 1:47 PM
|
|
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
|
|