我对Java线程和操作系统线程有疑问,我读了Java Threads vs Pthreads和Java Threads vs OS Threads,但我找不到我的困惑的答案。
在调用start()之前我曾考虑过,没有创建OS线程。
但根据https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.State.html,
尚未开始的主题处于
NEW
州。
我错了或者java doc中定义的状态不仅仅是标记Thread实例的状态吗?
我的问题是:
start()
答案 0 :(得分:2)
Thread thread = new Thread(){
@Override
public void run() {
// code
}
};
// at this point the thread is in NEW state, all you have a simple java object,
// no actual thread is created
thread.start();
// when start() is invoked, at some unspecified point in the near future
// the thread will go into RUNNABLE state, this means an actual thread will be created.
// That can happen before start() returns.