Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Object

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are Thread objects are like any other Objects of java.
 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Like all other classes, the Thread class too extends from the Object class. So it can be considered and treated as a 'normal object' in java.
 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiruka Sandev wrote:Yes. Like all other classes, the Thread class too extends from the Object class. So it can be considered and treated as a 'normal object' in java.


Then upon calling a start method of a thread object how a new method stack generated.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aruna Balasuriya wrote:Then upon calling a start method of a thread object how a new method stack generated.


Why don't you take a look at Thread's sources..? It's in src.zip in our JDK installation folder! You will see that the method that starts the new thread of execution is a native method:

 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To simply put it, that is how the start method in the Thread class has been implemented.

You may implement your class to do anything that you like, but that doesn't mean that an instance of your class cannot be considered to be a regular object in java.

For example say that you have written a class which has a method that writes a record to a DB when that method is invoked. Would you not consider an instance of your class to be like any other object in Java?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic