• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

priority doesn't show up in the output

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic