• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

THread Selection By JVM Problem

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's up to Thread scheduling by JVM.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic