Results 1 to 3 of 3
  1. #1
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Red face Java Thread Priorities

    Hello, Could anyone direct me to some official documentation that explains how Java Thread are prioritized. Also, could you go ahead and give me a brief description on how they are by default prioritized. For example, if I create two different threads doing two totally different things, will one of them by default have a higher priority or will they have equal priority?

    A project I am working on requires these two threads I've created to have an equal time-slice so to speak. I don't want one thread getting more attention than the other, regardless of what code is running in the threads.

    Thanks for your help!

    Monc

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    I've written a couple of articles on this topic that may be of interest. I wouldn't say they constitute "official documentation", but they're based on a fairly close reading of the JVM source code (Hotspot) and some reasonably authoritative works on how thread scheduling works in Windows and Linux:

  3. #3
    Moncleared is offline Member
    Join Date
    Jan 2009
    Posts
    92
    Rep Power
    0

    Default

    Correct me if I'm wrong, but after reading your first link it sounds like I'm not going to see much of a difference between which Thread gets executed more? I'm gathering this notion based on the analysis of the threads generating random numbers and 1-8 priorities practically generate the same amount while 9-10 generate significantly more (not much of a difference between 9-10 though).

    If this is the case and I keep in mind that Threads and Priorities can change based on OS and VM, I should be relatively safe in making the assumption that if I create two threads using the Default priority (or just not setting a priority) they'll likely get the same run time?

    I should also mention that I do not intend to deal with IO with these threads. They'll simply be changing global variables and such.

    Thanks!

    P.S. Great articles
    Last edited by Moncleared; 02-16-2009 at 09:19 PM.

Similar Threads

  1. Replies: 3
    Last Post: 11-06-2008, 05:24 PM
  2. How to use thread priorities
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 07:35 PM
  3. Replies: 0
    Last Post: 01-28-2008, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •