• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class extending thread  RSS feed

 
Vijay Tidake
Ranch Hand
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why above main method the first call print "A" and second is printing "B", although I am passing same job to both the thread?
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because your OS will allow which ever thread that is ready to go first, and it is not always the one you think it is.
 
Vijay Tidake
Ranch Hand
Posts: 148
Hibernate Java Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not about the sequence. Consider these as two different programs.
My question is if I am passing the Runnable job to class A (Thread), still it is not executing it class B.

If I dont override run in class A , both line will print B.?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Tidake wrote:
My question is if I am passing the Runnable job to class A (Thread), still it is not executing it class B.


It is the run() method of the Thread class that calls the run() method of the Runnable that is passed via the constructor. So, if you try to *both* pass a Runnable and override the run() method, then the latter will execute.

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