Priority Jumbles

R

Ravi

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.
 
J

Joshua Cranmer

Ravi said:
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.
 
E

Eric Sosman

Joshua Cranmer wrote On 03/05/07 17:10,:
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 ^
 
D

Daniel Pitts

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>
 
J

Joshua Cranmer

Eric said:
Joshua Cranmer wrote On 03/05/07 17:10,:

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.
 
P

Patricia Shanahan

Daniel said:
....

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
 
L

Lew

Joshua said:
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
 
C

Chris Uppal

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
 
R

Ravi

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.
 
L

Lew

Chris said:
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
 
E

Eric Sosman

Lew said:
[...]
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.
 
J

Joshua Cranmer

Eric said:
Lew said:
[...]
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)
 
J

Joshua Cranmer

Lew said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top