*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread join question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread join question" Watch "thread join question" New topic
Author

thread join question

Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
Refer to the code below...

I know nothing is truly 'guaranteed' in threading, but in the code example below, is it correct to say that the string "end concurrency" will NEVER be printed before mt1 and mt2 have each finished their run functions?

sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Hello Rachel. I guess you are right with your saying,that string "end concurrency" will NEVER be printed before mt1 and mt2 have each finished their run functions.
As you can see below i executed your code and found that Thread mt2 begins first and ends first followed by Thread mt1 followed by the string "end concurrency"

In thread mt2
In thread mt1
In thread mt1
In thread mt2
In thread mt1
In thread mt2
In thread mt1
In thread mt2
In thread mt1
In thread mt2
end concurrency)

But, as it is shown in the code that, it is thread mt2 that begins first, even though thread mt1 has a much higher priority in fact the highest priority in comparison with that of thread mt2.

Hope this helps!

Always believe in yourself
Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
sarvesh dikonda wrote:Hello Rachel. I guess you are right with your saying,that string "end concurrency" will NEVER be printed before mt1 and mt2 have each finished their run functions.
As you can see below i executed your code and found that Thread mt2 begins first and ends first followed by Thread mt1 followed by the string "end concurrency"

In thread mt2
In thread mt1
In thread mt1
In thread mt2
In thread mt1
In thread mt2
In thread mt1
In thread mt2
In thread mt1
In thread mt2
end concurrency)

But, as it is shown in the code that, it is thread mt2 that begins first, even though thread mt1 has a much higher priority in fact the highest priority in comparison with that of thread mt2.

Hope this helps!


thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread join question
 
Similar Threads
why when try won't throw a exception ,it can not compile?
notifyAll()
Another Question (.... Threads / join() )
exception is never thrown in try compiler error
help regarding synchronized methods