Java Forum / General / March 2007
Priority Jumbles
Ravi - 05 Mar 2007 20:28 GMT [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)); } } [/CODE]
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.
Joshua Cranmer - 05 Mar 2007 22:10 GMT > 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.
Eric Sosman - 05 Mar 2007 22:41 GMT Joshua Cranmer wrote On 03/05/07 17:10,:
>>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 [quoted text clipped - 8 lines] > "-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 ^
 Signature Eric.Sosman@sun.com
Joshua Cranmer - 06 Mar 2007 02:36 GMT > Joshua Cranmer wrote On 03/05/07 17:10,: >> [quoted text clipped - 12 lines] > > 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.
Lew - 07 Mar 2007 03:07 GMT Eric Sosman wrote:
>> 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. 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
Chris Uppal - 07 Mar 2007 04:33 GMT > 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
Ravi - 07 Mar 2007 07:14 GMT On Mar 6, 8:33 pm, "Chris Uppal" <chris.up...@metagnostic.REMOVE- THIS.org> wrote:
> > Eric Sosman wrote: > > > > std math abbr 4 "negative." lighten ^ [quoted text clipped - 10 lines] > > -- 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.
Lew - 07 Mar 2007 14:04 GMT >> 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... > [quoted text clipped - 3 lines] > > 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
Eric Sosman - 08 Mar 2007 02:05 GMT > [...] > 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.
 Signature Eric Sosman esosman@acm-dot-org.invalid
Joshua Cranmer - 08 Mar 2007 22:50 GMT >> [...] >> I was also challenging the description of "-ve" as a "std math abbr". [quoted text clipped - 6 lines] > 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)
Lew - 09 Mar 2007 02:26 GMT > No, you should be talking to the perpetrators of ... Lambda (the letter, not the word) ... Greece?
-- Lew
Joshua Cranmer - 10 Mar 2007 01:17 GMT >> 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.
Daniel Pitts - 06 Mar 2007 00:45 GMT > [CODE] > class NewThread implements Runnable { [quoted text clipped - 57 lines] > 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>
Patricia Shanahan - 06 Mar 2007 02:39 GMT ....
>> 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, [quoted text clipped - 8 lines] > <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
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|