Chan Ag wrote:A thread becomes alive ( a thread of execution - a thread in essence ) when the start() method is invoked on the thread object. It is considered dead when it moves out of its run() method. Between this period, a thread is considered to be alive and isAlive() check on the thread returns true.
When a thread ( remember even main() is a thread ) issues anotherThreadObject.join(), it joins anotherThreadObject. So it can resume only after anotherThreadObject has ended. i.e it becomes runnable only after anotherThreadObject has completed executing its run method ( i.e anotherThreadObject is no longer alive).
You might want to read Oracle docs for more information.
Chan.
[yes i knew ob1 is a instance of class of NewThread1 which doesn't have isAlive(), this might be the reason]
so here there are calling isAlive method using both reference variables rite, thats what questioning me! why use of both reference variables? can some one explain this concept generally?
this is what i understood. ob1 is an object contains which contains Thread type reference variable i.e t, since ob1 is instance of class NewThread1 which doesn't have isAlive(), join methods and those are present in Thread class and those can be accessible by Thread reference which is 't' here. so we are calling those methods as ob1.t.isAlive() and ob1.t.join(). am i rite?
Chan Ag wrote:
[yes i knew ob1 is a instance of class of NewThread1 which doesn't have isAlive(), this might be the reason]
Absolutely correct.
so here there are calling isAlive method using both reference variables rite, thats what questioning me! why use of both reference variables? can some one explain this concept generally?
Such multiple dots references should be evaluated from left to right.
You can invoke isAlive on a thread variable. So you want to do this.
threadReference.isAlive();
Now threadReference you do not have in your DemoJoin class. Where is the Thread variable? In your NewThread1 class, right. How do you access NewThread1 instance variables inside DemoJoin. instance variable.the variable you require / instance variable.getVariable().
Since you don't have a getter, your threadReference, i.e (t) becomes
object reference.variable reference ( obj1.t ).
Replace that in the threadReference.isAlive(), and you get
ob1.t.isAlive()
this is what i understood. ob1 is an object contains which contains Thread type reference variable i.e t, since ob1 is instance of class NewThread1 which doesn't have isAlive(), join methods and those are present in Thread class and those can be accessible by Thread reference which is 't' here. so we are calling those methods as ob1.t.isAlive() and ob1.t.join(). am i rite?
You know it is 'right', not 'rite'. Right?
And yes, you're right.
Chan.
Don't get me started about those stupid light bulbs. |