aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread topic  Help  needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread topic  Help  needed" Watch "Thread topic  Help  needed" New topic
Author

Thread topic Help needed

ramya ray
Ranch Hand

Joined: Aug 11, 2006
Posts: 101
Hi ,
Please guide what can be circumstances a thread can move from running to runnable..

I think one is calling yield ,other is Thread schedular means higher priority thread has come or based on time slicing...

Are there any others .Please help.


Thanks ,
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

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
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
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
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.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
wait/sleep/yield are non-runnable states.

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 ]

Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread topic Help needed