Well, I am not sure as to what this has to do with the SCJP -- but then again, I don't know what's on the test these days.
Anything that can cause the current thread to block, should cause a context switch -- reading/writing to a file, reading/writing to a network, synchronizing on a lock that is already owned, etc.
Wouldn't be "some time passed" also be a cause? I think the JVM switches from thread to thread also in a time dependent way. I mean independently of prioties or calling yield().
Another question: Does this also count? "The scheduler of the system selects another application than JVM."
Yours, Bu.
all events occur in real time
ramya ray
Ranch Hand
Joined: Aug 11, 2006
Posts: 101
posted
0
Henry, whaterver be in exam these days, but it is covered by K & B book can i be that much sure
Thanks . [ February 15, 2007: Message edited by: ramya ray ]
Cheryl Gray
Ranch Hand
Joined: Nov 17, 2000
Posts: 44
posted
0
I think it would be platform dependent. Some will offer time slicing and others will offer thread priorities. I guess calling sleep() would be a way too.
Anything is possible to those who believe.
Remko Strating
Ranch Hand
Joined: Dec 28, 2006
Posts: 893
posted
0
sleep() wil not put a thread from running to runnable.
A Thread wil go back to the runnable state after the time which is specified in te sleep command.
The following is the life cycle of a thread after invoking a start method using Thread object.
1) runnable 2) running 3) non-runnable(sleep/wait/yield) 4) dead
yield ---> when a thread calls this method it steps back to to to a non runnable the other threads having same priority or higher than the current thread are given chance to go into running state. This is arbitrary it is quite possible that a thread might go to a non runnable state and the same thread comes to runnable state and then directly go to running state without giving chance to other threads (of same priority). Please remember, yield is a static method.
sleep ---> Sleep will put a current running thread to sleep for a millisecond defined in its argument list (eg: sleep(1000) implies 1000 millisecond). This method will put the current thread into non runnable state. the thread can be back to runnable state after the time elapsed to it gets over. sleep is static method belong to Thread class.
OS is mostly responsible for scheduling threads to run, till what time etc... If i guess right Windows implements time-slicing and linux schedules according to thread priorities. [ February 15, 2007: Message edited by: Atul Savant ]