Dado o código:
import java.lang.Thread;
import java.lang.Runnable;
public class TestThread {
public static void main(String[] args) {
Thread t = new Thread(new DoIt());
System.out.println(“Acabamos de criar: ” + t.getState());
t.start();
}
}
class DoIt implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getState());
}
}
Output:
Acabamos de criar: NEW
RUNNABLE
Dentro do método run da classe DoIt, a mensagem retornada não deveria ser RUNNING ao invés de RUNNABLE visto que no momento em que a chamada do “sout” acontece, a thread em questão tem que estar executando?
__________________________________________________________________________________________
There is no such “RUNNING” state in java.lang.Thread.State enum class, However RUNNABLE indicates
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.
Colado de <http://download.oracle.com/javase/6/docs/api/java/lang/Thread.State.html#RUNNABLE>
RUNNABLE:
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.
Colado de <