• 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

Thread Priority

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a question about how threads and setting their priority works. I am playing with this code now on sun jdk 1.5 on linux:



I won't put all of the output here but just the first few lines go like this:


so it looks like even after t3 (highest priority thread) is started, it continues to process t2 (lower priority of 5). and actually it will process t2 for quite some time before coming to t3 in my latest run but sometimes it will return to t1 and finish t3 last. i thought the MAX_PRIORITY means it should go first?
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, the code in my previous post has a bug... it should say everything else is the same though.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so it looks like even after t3 (highest priority thread) is started, it continues to process t2 (lower priority of 5). and actually it will process t2 for quite some time before coming to t3 in my latest run but sometimes it will return to t1 and finish t3 last. i thought the MAX_PRIORITY means it should go first?



Basically, when you have two (or more) threads in a runnable state, the one would the higher priority should run more often. Unfortunately, you don't have any threads that are in a run state too often. Your threads spent most of its time in the blocked state, as it is trying to write IO to the screen.

Anyway, try this... I slightly modified your runner to be more cpu bound, instead of IO bound.



Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic