Priority Jumbles

Discussion in 'Java' started by Ravi, Mar 5, 2007.

  1. Ravi

    Ravi Guest

    Code:
    class NewThread implements Runnable {
            long counter=0;
            Thread t;
            private volatile boolean running = true;
    
            NewThread(String threadName, int priority) {
                    t = new Thread(this,threadName);
                    t.setPriority(priority);
            }
    
            public void run() {
                    while (running)
                            counter++;
            }
    
            public void stop() {
                    running = false;
            }
    
    }
    
    class PriorityDemo {
            public static void main(String args[]) {
                    NewThread n1 = new
    NewThread("n1",Thread.MAX_PRIORITY);
                    NewThread n2 = new
    NewThread("n2",Thread.MIN_PRIORITY);
                    n1.t.start();
                    n2.t.start();
    
                    try {
                            Thread.sleep(10000);
                    } catch(InterruptedException e) {
                            System.out.println(e);
                    }
    
                    n1.stop();
                    n2.stop();
    
                    try {
                            n1.t.join();
                            n2.t.join();
                    } catch(InterruptedException e) {
                            System.out.println(e);
                    }
    
                    System.out.println("n1.counter = "+n1.counter);
                    System.out.println("n2.counter = "+n2.counter);
                    System.out.println("difference = "+(n1.counter-
    n2.counter));
            }
    }
    
    this code is to demonstrate the use of priority levels in the Java,
    by conting how many times the vaiable counter gets incremented in each
    loop.
    i compiled it with jdk6 and run it under jre6 in Linux 2.6.19 kernel.
    but sometimes i get a -ve diffrence. Can sb pls explain how this
    happens as i ve used the man and min priority here.
     
    Ravi, Mar 5, 2007
    #1
    1. Advertising

  2. Ravi wrote:
    > this code is to demonstrate the use of priority levels in the Java,
    > by conting how many times the vaiable counter gets incremented in each
    > loop.
    > i compiled it with jdk6 and run it under jre6 in Linux 2.6.19 kernel.
    > but sometimes i get a -ve diffrence. Can sb pls explain how this
    > happens as i ve used the man and min priority here.
    >


    This is not an IM chat room. You are not being charged for length of
    message. Therefore, use proper spelling, grammar, and don't abbreviate
    unless it is clearer abbreviated. I don't understand what you mean by
    "-ve diffrence", but I'm assuming what you're saying is that there is no
    noticeable difference between maximum and minimum priority.

    Somewhere within the specifications (probably java.lang.Thread), it
    states that the priority is only a guideline for the virtual machine.
    Therefore maximum priority threads do not necessarily have higher
    priority than minimum priority threads.
     
    Joshua Cranmer, Mar 5, 2007
    #2
    1. Advertising

  3. Ravi

    Eric Sosman Guest

    Joshua Cranmer wrote On 03/05/07 17:10,:
    > Ravi wrote:
    >
    >>this code is to demonstrate the use of priority levels in the Java,
    >>by conting how many times the vaiable counter gets incremented in each
    >>loop.
    >>i compiled it with jdk6 and run it under jre6 in Linux 2.6.19 kernel.
    >>but sometimes i get a -ve diffrence. Can sb pls explain how this
    >>happens as i ve used the man and min priority here.
    >>

    >
    >
    > This is not an IM chat room. You are not being charged for length of
    > message. Therefore, use proper spelling, grammar, and don't abbreviate
    > unless it is clearer abbreviated. I don't understand what you mean by
    > "-ve diffrence", but I'm assuming what you're saying is that there is no
    > noticeable difference between maximum and minimum priority.


    std math abbr 4 "negative." lighten ^

    --
     
    Eric Sosman, Mar 5, 2007
    #3
  4. Ravi

    Daniel Pitts Guest

    On Mar 5, 12:28 pm, "Ravi" <> wrote:
    >
    Code:
    > class NewThread implements Runnable {
    >         long counter=0;
    >         Thread t;
    >         private volatile boolean running = true;
    >
    >         NewThread(String threadName, int priority) {
    >                 t = new Thread(this,threadName);
    >                 t.setPriority(priority);
    >         }
    >
    >         public void run() {
    >                 while (running)
    >                         counter++;
    >         }
    >
    >         public void stop() {
    >                 running = false;
    >         }
    >
    > }
    >
    > class PriorityDemo {
    >         public static void main(String args[]) {
    >                 NewThread n1 = new
    > NewThread("n1",Thread.MAX_PRIORITY);
    >                 NewThread n2 = new
    > NewThread("n2",Thread.MIN_PRIORITY);
    >                 n1.t.start();
    >                 n2.t.start();
    >
    >                 try {
    >                         Thread.sleep(10000);
    >                 } catch(InterruptedException e) {
    >                         System.out.println(e);
    >                 }
    >
    >                 n1.stop();
    >                 n2.stop();
    >
    >                 try {
    >                         n1.t.join();
    >                         n2.t.join();
    >                 } catch(InterruptedException e) {
    >                         System.out.println(e);
    >                 }
    >
    >                 System.out.println("n1.counter = "+n1.counter);
    >                 System.out.println("n2.counter = "+n2.counter);
    >                 System.out.println("difference = "+(n1.counter-
    > n2.counter));
    >         }}
    >
    > 
    >
    > this code is to demonstrate the use of priority levels in the Java,
    > by conting how many times the vaiable counter gets incremented in each
    > loop.
    > i compiled it with jdk6 and run it under jre6 in Linux 2.6.19 kernel.
    > but sometimes i get a -ve diffrence. Can sb pls explain how this
    > happens as i ve used the man and min priority here.


    You're benchmark isn't a good one, it doesn't account for interaction
    of the JIT compiler. Its quite possible that since n1 starts first,
    the JIT compiler compiles and optimizes the loop in that thread, which
    causes a momentary delay. While this delay is happening on thread 1,
    thread 2 continues to run as expected, and counts higher than thread
    1.

    As a general rule, thread priorities in Java shouldn't be relied on to
    do anything specific.

    <http://tns-www.lcs.mit.edu/manuals/java-tutorial/java/threads/
    priority.html>
     
    Daniel Pitts, Mar 6, 2007
    #4
  5. Eric Sosman wrote:
    > Joshua Cranmer wrote On 03/05/07 17:10,:
    >> Ravi wrote:
    >>
    >>> this code is to demonstrate the use of priority levels in the Java,
    >>> by conting how many times the vaiable counter gets incremented in each
    >>> loop.
    >>> i compiled it with jdk6 and run it under jre6 in Linux 2.6.19 kernel.
    >>> but sometimes i get a -ve diffrence. Can sb pls explain how this
    >>> happens as i ve used the man and min priority here.
    >>>

    >>
    >> This is not an IM chat room. You are not being charged for length of
    >> message. Therefore, use proper spelling, grammar, and don't abbreviate
    >> unless it is clearer abbreviated. I don't understand what you mean by
    >> "-ve diffrence", but I'm assuming what you're saying is that there is no
    >> noticeable difference between maximum and minimum priority.

    >
    > std math abbr 4 "negative." lighten ^
    >

    1. I don't use any math abbreviation unless it is a distinct symbol, and
    even then, only for implies and therefore.

    2. I prefer treating the English language with respect.
     
    Joshua Cranmer, Mar 6, 2007
    #5
  6. Daniel Pitts wrote:
    > On Mar 5, 12:28 pm, "Ravi" <> wrote:

    .....
    >> this code is to demonstrate the use of priority levels in the Java,
    >> by conting how many times the vaiable counter gets incremented in each
    >> loop.

    ....
    >
    > You're benchmark isn't a good one, it doesn't account for interaction
    > of the JIT compiler. Its quite possible that since n1 starts first,
    > the JIT compiler compiles and optimizes the loop in that thread, which
    > causes a momentary delay. While this delay is happening on thread 1,
    > thread 2 continues to run as expected, and counts higher than thread
    > 1.
    >
    > As a general rule, thread priorities in Java shouldn't be relied on to
    > do anything specific.
    >
    > <http://tns-www.lcs.mit.edu/manuals/java-tutorial/java/threads/
    > priority.html>
    >


    Arguably, it is an excellent demonstration of the behavior of Java
    priority levels. It brings out the fact that one should never depend on
    the priorities to ensure order, because a minimum priority thread can
    get CPU time even when there is a maximum priority thread in the system.

    Patricia
     
    Patricia Shanahan, Mar 6, 2007
    #6
  7. Ravi

    Lew Guest

    Eric Sosman wrote:
    >> std math abbr 4 "negative." lighten ^


    Joshua Cranmer wrote:
    > 1. I don't use any math abbreviation unless it is a distinct symbol, and
    > even then, only for implies and therefore.
    >
    > 2. I prefer treating the English language with respect.


    Furthermore, the original post was not comprehensible, to me at least. I had
    never seen "-ve" before and I have a maths degree - not a standard
    abbreviation in my world at all.

    Besides, l33t is just plain ugly and illiterate.

    I guess if people want to be obscure and hard to understand, quite aside from
    stylistic considerations, they can do whatever they want. Personally, I prefer
    not having to work so hard to read someone's post, especially when they are
    enticing me to provide free help (which in my case may be worth every pfennig).

    People are free to disregard Joshua's and my advice, and I am free to look
    with superior egoistic disdain upon their intellectual laziness.

    -- Lew
     
    Lew, Mar 7, 2007
    #7
  8. Ravi

    Chris Uppal Guest

    Lew wrote:
    > Eric Sosman wrote:
    > > > std math abbr 4 "negative." lighten ^


    > People are free to disregard Joshua's and my advice, and I am free to look
    > with superior egoistic disdain upon their intellectual laziness.


    Y'know...

    I think of better people to say that about than Eric. One of the finest --
    probably /the/ finest -- user (and abuser) of the English language to
    contribute to this group.

    Or did y'all not notice ?

    -- chris
     
    Chris Uppal, Mar 7, 2007
    #8
  9. Ravi

    Ravi Guest

    On Mar 6, 8:33 pm, "Chris Uppal" <-
    THIS.org> wrote:
    > Lew wrote:
    > > Eric Sosman wrote:
    > > > > std math abbr 4 "negative." lighten ^

    > > People are free to disregard Joshua's and my advice, and I am free to look
    > > with superior egoistic disdain upon their intellectual laziness.

    >
    > Y'know...
    >
    > I think of better people to say that about than Eric. One of the finest --
    > probably /the/ finest -- user (and abuser) of the English language to
    > contribute to this group.
    >
    > Or did y'all not notice ?
    >
    > -- chris


    I am really sorry. This is the first time I've ever posted on Google
    groups. Earlier, I used to discuss in forums which were much used to
    the language I've used here.
     
    Ravi, Mar 7, 2007
    #9
  10. Ravi

    Lew Guest

    >> Eric Sosman wrote:
    >>>> std math abbr 4 "negative." lighten ^

    >
    > Lew wrote:
    >> People are free to disregard Joshua's and my advice, and I am free to look
    >> with superior egoistic disdain upon their intellectual laziness.


    Chris Uppal wrote:
    > Y'know...
    >
    > I think of better people to say that about than Eric. One of the finest --
    > probably /the/ finest -- user (and abuser) of the English language to
    > contribute to this group.
    >
    > Or did y'all not notice ?


    I was not saying anything about Eric. I respect Eric's use of language, and
    his "lighten ^" was actually quite clever. I was speaking generally about
    requesting fuller English. (And specifically about my own egoism.) Eric was
    not the one whose message triggered the conversation.

    I was also challenging the description of "-ve" as a "std math abbr".

    -- Lew
     
    Lew, Mar 7, 2007
    #10
  11. Ravi

    Eric Sosman Guest

    Lew wrote:
    > [...]
    > I was also challenging the description of "-ve" as a "std math abbr".


    Well, perhaps I should have called it a "std engnr abbr."
    Next week, we'll do "+ve."

    For the record, my degree, too, was in Mathematics (although
    no one would mistake me for a mathematician). It doesn't seem to
    me that the perpetrators of "QED" and "lim inf" and "O(e^x)" have
    much cause to disparage abbreviation.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Mar 8, 2007
    #11
  12. Eric Sosman wrote:
    > Lew wrote:
    >> [...]
    >> I was also challenging the description of "-ve" as a "std math abbr".

    >
    > Well, perhaps I should have called it a "std engnr abbr."
    > Next week, we'll do "+ve."
    >
    > For the record, my degree, too, was in Mathematics (although
    > no one would mistake me for a mathematician). It doesn't seem to
    > me that the perpetrators of "QED" and "lim inf" and "O(e^x)" have
    > much cause to disparage abbreviation.
    >

    No, you should be talking to the perpetrators of OASIS, CPU, IDE, SCSI,
    SATA, HDD, GNU, LISP, FORTRAN, Lambda (the letter, not the word), OTOH
    SSCCE, regex, etc. (i.e., the CS dep'ts)
     
    Joshua Cranmer, Mar 8, 2007
    #12
  13. Ravi

    Lew Guest

    Joshua Cranmer wrote:
    > No, you should be talking to the perpetrators of ... Lambda (the letter, not the word) ...


    Greece?

    -- Lew
     
    Lew, Mar 9, 2007
    #13
  14. Lew wrote:
    > Joshua Cranmer wrote:
    >> No, you should be talking to the perpetrators of ... Lambda (the
    >> letter, not the word) ...

    >
    > Greece?
    >
    > -- Lew
    >

    Lambda = null. Just ask my history teachers (I write history notes using
    a combination of math, comp sci, and abbreviations up the wazoo.
     
    Joshua Cranmer, Mar 10, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mosow

    aspnet_wp.exe priority

    mosow, Apr 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    384
    mosow
    Apr 16, 2004
  2. Replies:
    1
    Views:
    512
    Bruce Barker
    Nov 10, 2005
  3. Amil
    Replies:
    2
    Views:
    1,346
  4. Alistair Atkinson

    Setting the priority a WebStart app

    Alistair Atkinson, Sep 20, 2003, in forum: Java
    Replies:
    5
    Views:
    392
    Alistair Atkinson
    Sep 24, 2003
  5. Marcel Müller
    Replies:
    3
    Views:
    575
    Marcel Müller
    Apr 27, 2009
Loading...

Share This Page