File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes priority doesn't show up in the output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "priority doesn Watch "priority doesn New topic
Author

priority doesn't show up in the output

Arul Jose
Ranch Hand

Joined: Jan 14, 2005
Posts: 131
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.
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
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
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: priority doesn't show up in the output