This week's book giveaway is in the JavaFX forum. We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line! See this thread for details.

I am creating two thread objects and making them print from 0 to 9. I am setting different priorities. But the priorities doesn't show up in the output at all. I would like to know why.

the output is always :

Call Order : 1 iteration : 0 Call Order : 2 iteration : 0 Call Order : 1 iteration : 1 Call Order : 2 iteration : 1 Call Order : 1 iteration : 2 Call Order : 2 iteration : 2 Call Order : 1 iteration : 3 Call Order : 2 iteration : 3 Call Order : 1 iteration : 4 Call Order : 2 iteration : 4 Call Order : 1 iteration : 5 Call Order : 2 iteration : 5 Call Order : 1 iteration : 6 Call Order : 2 iteration : 6 Call Order : 1 iteration : 7 Call Order : 2 iteration : 7 Call Order : 1 iteration : 8 Call Order : 2 iteration : 8 Call Order : 1 iteration : 9 Call Order : 2 iteration : 9

I expected something like the following Call Order : 1 iteration : 0 Call Order : 2 iteration : 0 Call Order : 2 iteration : 1 Call Order : 1 iteration : 1 Call Order : 2 iteration : 2 Call Order : 2 iteration : 3 Call Order : 1 iteration : 2

that is i expected more priority for the second thread.

Just speculation, but your thread process is not very busy, it prints a message and then sleeps for 20 mSec. It may be that, in the grand scheme of things, the lower priority thread is running (printing the line) then going to sleep, then the high priority thread is dispatched and run (prints it's line) and then goes to sleep for 20 mSec, and low priorities "sleep time" expires and it is made runnable, while the high priority thread is still in it's sleep so the low priority thread is dispatched as the highest running "runnable" thread at that time.

It just may be that the activity is not intense enought to cause contention for execution time.

------------------------
Bob
SCJP - 86% - June 11, 2009

Hi Arul, I have also run your code.Output which i am getting is ,i think what you were expecting : Call Order : 2 iteration : 0 Call Order : 1 iteration : 0 Call Order : 2 iteration : 1 Call Order : 1 iteration : 1 Call Order : 2 iteration : 2 Call Order : 1 iteration : 2 Call Order : 2 iteration : 3 Call Order : 1 iteration : 3 Call Order : 2 iteration : 4 Call Order : 1 iteration : 4 Call Order : 2 iteration : 5 Call Order : 1 iteration : 5 Call Order : 2 iteration : 6 Call Order : 1 iteration : 6 Call Order : 2 iteration : 7 Call Order : 2 iteration : 8 Call Order : 1 iteration : 7 Call Order : 2 iteration : 9 Call Order : 1 iteration : 8 Call Order : 1 iteration : 9