• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

THread Selection By JVM Problem

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KB BOOK CHAPTER:THREADS


output:

m1 r1 r2 m2


----------------------


Queries:

1.In the book is mentioned that
a.The output could be r1 r2 m1 m2
b.The output could be m1 r1 r2 m2


how is the case a possible.
is it that the main thread runs after the thread t ?
if that is the case then,since the t THread object is created in the main Thread itself
how would thread t run since main thread runs after it.
 
Faisal A Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it that the main thread runs after the thread t ?

After thread t is started, which thread will run is unpreditable at any given time.

If that is the case then,since the t THread object is created in the main Thread itself
how would thread t run since main thread runs after it.


When thread t is started, both main and t are running concurrently, which one is given the time to execute is unpreditable.
The only predictablilty in this case is that m2 will always be last due to the t.join(). The others before m2 can be in any order.

Regards


 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's up to Thread scheduling by JVM.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic