• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Thread topic Help needed

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ,
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ramya ray
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic