*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes THread Selection By JVM Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "THread Selection By JVM Problem" Watch "THread Selection By JVM Problem" New topic
Author

THread Selection By JVM Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

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.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Faisal A Khan
Greenhorn

Joined: Jul 02, 2010
Posts: 11
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

Joined: Nov 04, 2009
Posts: 2066

It's up to Thread scheduling by JVM.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: THread Selection By JVM Problem
 
Similar Threads
wait() releases all locks?
Question ID :988384705515 JQ+
Exercise 13.6 in - A Programmer's Guide to Java SCJP Certification - 3rd Ed
Increment
Thread join()