• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread RUNNABLE vs RUNNING

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given this example:




Output:
Recently created: NEW
RUNNABLE

inside the run method of class DoIt, the message should not be returned RUNNING instead of RUNNABLE since at the time of the call "System.out.println(Thread.currentThread().getState());" happens, the thread in question has to be running and not just eligible to run?
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pedro abs wrote:Given this example:




Output:
Recently created: NEW
RUNNABLE

inside the run method of class DoIt, the message should not be returned RUNNING instead of RUNNABLE since at the time of the call "System.out.println(Thread.currentThread().getState());" happens, the thread in question has to be running and not just eligible to run?



There is no such "RUNNING" state in java.lang.Thread.State enum class, However RUNNABLE indicates

http://download.oracle.com/javase/6/docs/api/java/lang/Thread.State.html#RUNNABLE wrote:A thread in the runnable state is executing in the Java virtual machine but it may be waiting for other resources from the operating system such as processor.



Hope this helps

Minhaj
 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi abs,

The API states:

public static enum Thread.State
extends Enum<Thread.State>

A thread state. A thread can be in one of the following states:

NEW
A thread that has not yet started is in this state.
RUNNABLE
A thread executing in the Java virtual machine is in this state.
BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.
WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
TERMINATED
A thread that has exited is in this state.
A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states.


I think it is unable to determine whether it is RUNNABLE or RUNNING, because the context-switching is operating system dependent, therefore there is no such constant named RUNNING, which is why Thread.yield() method have not guaranteed behavior.

Hello Ranchers please confirm

Thank You
 
Quick! Before anybody notices! Cover it up with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic