Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread questions  RSS feed

 
Sanny kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please answer the questions?
1.What is the type of the �target� data member of the Thread class?
2.How is �target� used to support running direct subclass of the Thread class versus running class implementing Runnable interface?

Thanks
Santhosh
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanny kumar:
Hi,

Can you please answer the questions?
1.What is the type of the �target� data member of the Thread class?
2.How is �target� used to support running direct subclass of the Thread class versus running class implementing Runnable interface?

Thanks
Santhosh


The "target" instance variable of the Thread class is an internal private variable. It is not officially documented, and hence, subject to change in future implementations.

In the current implementation, it is used to store the Runnable object that is passed to the Thread object (assuming the constructor that takes the Runnable is used). The default run() method, if the method has not been overridden, will check the target variable for a Runnable object. And if one exist, it will call the run() method of the runnable object.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!