Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Priority Jumbles

Reply
Thread Tools

Priority Jumbles

 
 
Ravi
Guest
Posts: n/a
 
      03-05-2007
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.

 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      03-05-2007
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.
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      03-05-2007
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 ^

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      03-06-2007
On Mar 5, 12:28 pm, "Ravi" <(E-Mail Removed)> 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/j.../java/threads/
priority.html>

 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      03-06-2007
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.
 
Reply With Quote
 
Patricia Shanahan
Guest
Posts: n/a
 
      03-06-2007
Daniel Pitts wrote:
> On Mar 5, 12:28 pm, "Ravi" <(E-Mail Removed)> 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/j.../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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-07-2007
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
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      03-07-2007
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


 
Reply With Quote
 
Ravi
Guest
Posts: n/a
 
      03-07-2007
On Mar 6, 8:33 pm, "Chris Uppal" <(E-Mail Removed)-
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.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-07-2007
>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
efficient priority queue for a few descrete priority levels Marcel Müller C++ 3 04-27-2009 03:22 PM
D300 BUG in Aperture Priority & Shutter Priority Mode Chico Digital Photography 21 06-23-2008 01:55 PM
Shutter Priority Vs. Aperture Priority Question mutefan@yahoo.com Digital Photography 13 09-14-2006 03:51 PM
Should I use shutter-priority or appurature-priority? ½ Confused Digital Photography 4 02-22-2006 09:48 AM
Question about Aperture priority and Shutter Priority John Edwards Digital Photography 8 01-05-2005 04:58 PM



Advertisments