This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread join question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: thread join question
 
Similar Threads
notifyAll()
Another Question (.... Threads / join() )
exception is never thrown in try compiler error
why when try won't throw a exception ,it can not compile?
help regarding synchronized methods