• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

what does the statement in the given thread program meant?

 
Ranch Hand
Posts: 94
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


the statements like ob1.t.isAlive(), ob1.t.join() etc in above program. we can call a method using its object. but here we are calling isAlive() and join() on two objects. what is the name of this concept. what the theory behind it. explain or give a link to understand this concept.
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


thank you for your reply chan and
actually my doubt is we are calling isAlive or join methods as ob1.t.isAlive() and ob1.t.join(), why can't we call it as ob1.isAlive()[yes i knew ob1 is a instance of class of NewThread1 which doesn't have isAlive(), this might be the reason]. here ob1 and t are both reference variables. where t is Thread type reference variable. so here we 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.instance 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
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


[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.


 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.




thanks a lot now i understood it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic