From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5392,b15c78c1a4e44293 X-Google-Attributes: gidf5392,public X-Google-Thread: 108717,b15c78c1a4e44293 X-Google-Attributes: gid108717,public X-Google-Thread: 1103af,b15c78c1a4e44293 X-Google-Attributes: gid1103af,public X-Google-Thread: fa528,b15c78c1a4e44293 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2004-02-29 13:21:55 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: rdgentry1@cablelynx.com (P Gentry) Newsgroups: comp.unix.tru64,comp.os.linux.misc,comp.os.linux.development.system,comp.programming Subject: Re: Java Threads scheduling: Determinitic? Date: 29 Feb 2004 13:21:55 -0800 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 24.204.25.164 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1078089715 18736 127.0.0.1 (29 Feb 2004 21:21:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 29 Feb 2004 21:21:55 +0000 (UTC) Xref: archiver1.google.com comp.unix.tru64:11258 comp.os.linux.misc:17618 comp.os.linux.development.system:2929 comp.programming:12746 anne_dolly00@yahoo.co.uk (Anne) wrote in message news:... > Heya, > > From the following link: > http://java.sun.com/docs/books/tutorial/essential/threads/priority.html > It is said that: > < algorithm known as fixed priority scheduling>>. The algorithms are > particularly deterministic! > > The link includes two threads (of equal priority scheduling order) > code. > The run method for these two threads is > public void run() { > while (tick < 400000) { > tick++; > if ((tick % 50000) == 0) > System.out.println("Thread #" + num > + ", tick = " + tick); > } > } > This run method contains a tight loop that increments the integer tick > and every 50,000 ticks prints out the thread's identifier and its tick > count. > In execution on a time sliced operating systems,the output might look > like: > Thread #1, tick = 50000 > Thread #0, tick = 50000 > Thread #0, tick = 100000 > Thread #1, tick = 100000 > Thread #1, tick = 150000 > Thread #1, tick = 200000 > Thread #0, tick = 150000 > Thread #0, tick = 200000 > Thread #1, tick = 250000 > Thread #0, tick = 250000 > Thread #0, tick = 300000 > Thread #1, tick = 300000 > Thread #1, tick = 350000 > Thread #0, tick = 350000 > Thread #0, tick = 400000 > Thread #1, tick = 400000 > > As mentioned in the article: > << time-sliced system divides the CPU into time slots and iteratively > gives each of the equal-and-highest priority threads a time slot in > which to run. The time-sliced system iterates through the > equal-and-highest priority threads, allowing each one a bit of time to > run, until one or more of them finishes or until a higher priority > thread preempts them.>> > Then the article went on saying: > < what order threads are scheduled to run>>, altough the article claims > (see above) that JRE supports deterministic scheduling algorithm! > > Personally,I can't understand from the above program output why some > threads gets longer CPU quantum than others although they have the > same priority and instantiates the same class, thus similar (CPU, I/O) > dynamic utilisation. > Since a time sliced OS uses a same time quantum value, and the above > two threads moving through the same states [runnable, running, > blocked],I expect that each thread will have similar CPU quantums > number, and therefore the interleaving between the threads > (instantiating the same class) should be regular, i.e. N successive > CPU shots for thread1 then N successive CPU shots for thread 2, M > successive CPU shots for thread1 then M successive CPU shots for > thread 2, etc?.which is not the case. > > Is there anything i am missing? is the issue related to how the JRE > coordinates with the underlying OS? how , i really wonder? > > Besides, if we run the same program, we end up with different outputs; > personally I expect only a possibe change on the threads order of > execution. > > When running this program on a non-time-sliced system, however, you > will see messages from one thread finish printing before the other > thread ever gets a chance to print one message. Like this: > Thread #0, tick = 50000 > Thread #0, tick = 100000 > Thread #0, tick = 150000 > Thread #0, tick = 200000 > Thread #0, tick = 250000 > Thread #0, tick = 300000 > Thread #0, tick = 350000 > Thread #0, tick = 400000 > Thread #1, tick = 50000 > Thread #1, tick = 100000 > Thread #1, tick = 150000 > Thread #1, tick = 200000 > Thread #1, tick = 250000 > Thread #1, tick = 300000 > Thread #1, tick = 350000 > Thread #1, tick = 400000 > > Does it mean that System.println() is not a blocking system call. I > was expecting the thread to move to a blocking state. > > Thanks for ur help Of no specific knowledgeable help with your question but just happened to run into this 2 days ago. Perhaps it will be of interest to you. It discusses some shortcomings of the memory model spec and its effects on thread execution in some general terms. http://www-106.ibm.com/developerworks/library/j-jtp02244.html regards, prg email above disabled