Since Thread.yield() is called inside main() and works on currently executing thread.so main thread itself would run and would yield().Another thread spawned works in parallel but code inside main is executed by main thread.
Joined: Jun 18, 2007
marc, I think currently running thread is a. I think. Correct me if I am wrong.
Originally posted by dolly shah: In this piece of code currently executing thread is a (after a.start()). I think.
Thread 'a' might run after a.start() is called, but it's not running when Thread.yield() is called. Ask yourself: Is this line of code called by the run() method of thread 'a'? If not, how could it execute in thread 'a'?
(And as Yogesh pointed out, this has nothing to do with thread priorities.)
Joined: Sep 17, 2007
I thought the answer to this is main.
i understood from the above post the currently running thread will yield. but yield is called in main thread only. so when the main thread runs and hits the call to yield, then it will yield to any equal priority threads if there are any.
a and b thread do not have a yield in its run method or anymethod that run method calls.
Originally posted by mary john: ...it will yield to any equal priority threads if there are any...
When a thread yields, the platform-dependent thread scheduler determines what other threads might run, and priorities are not a good bet.
As Horstmann and Cornell warn on page 19 of Core Java 2: Volume II -- Advanced Features...
...thread priorities are highly system dependent...
For example, Windows NT/XP has seven priority levels. Some of the Java priorities will map to the same operating system level. In the Sun JVM for Linux, thread priorities are ignored altogether -- all threads have the same priority.
Thus, it is best to treat thread priorities only as hints to the scheduler...
"In the Sun JVM for Linux, thread priorities are ignored altogether -- all threads have the same priority." I can attest to the fact that priorities are ignored on Linux JDK. I'm using Kubuntu 7x (kernal 2.6.xx) with 1.6jdk and I've tried the MIN_PRIORITY vs MAX_PRIORITY and also numbers between 1-10, etc., and see no change in my output. Threading seems to be dolled out very 'fairly' in general. I wish I read this thread first! I was starting to wonder what the heck was going on LOL
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com