Given a reference called t to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute? 1) t.yield(); 2) yield(); 3) yield(100); 4) yield(t); The answer says 1 and 2. i'm confused about the inclusion of option 2. My reasoning: eg
From the example above i don't think t is paused..
Hi chafule read the que. >>a reference called t to a class which extends Thread and you are calling yield() on t. In your example you are creating two threads. One is executing default run() of Thread class and other is executing overridden run() of S class. and when you call s.yield() it puts S's run() to ready to run state giving other thread chance to execute, while Thread's run() might be running. AW your code won't compile as you are not assigning any object to t ref. (I liked the signature "I don't have compiler else I would have tried.") CMIW HTH [ March 03, 2002: Message edited by: Ravish Kumar ]
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Besides, yield is a static method of of class Thread, can be called from another class static method main without requiring any object reference. Right? HTH, - Manish
Joined: Feb 09, 2002
Sorry if i provided an inaccurate example
Ravish, what you provided did not answer the question. What i was asking was that by calling yield() on the current thread it does not mean that the thread object referenced by t will pause and let other thread run. calling yield() on the current thread may in effect cause the current thread to pause and let the thread referenced by t run ( as opposed to change t's state into non-runnable) Anyone else please feel free to correct me. TIA
I agree Chafule yield is static so it's the same call it on any object, even with no one and from within a static context: the current thread would pass to ready state. Thus both 1 and 2 could be either well or wrong depending if the running thread is the one pointed by t. I guess question is not very good.