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

Problem with output of The Code

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the following code , the ds.g() is getting called first after that the thread named ds.f() is being started but according to the code, the thread should get called first.



 
Henry Wong
author
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the following code , the ds.g() is getting called first after that the thread named ds.f() is being started but according to the code, the thread should get called first.


Not true. Once the new thread is started, it is now running independent of the main thread. So, whether the f() method or the g() method gets called first depends on the processor, the OS, priority, etc. These two threads are now racing each other, and on some OSes, f() will be called first, on others, g() will execute first.

Henry
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic