答:不可以
原因:java运行在虚拟机上,无法直接操作硬件,在start方法中调用了本地方法start0(),这是一个通过C++操作的方法。
底层源码:
package java.lang;
public class Thread implements Runnable {
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
/* Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented. */
group.add(this);
boolean started = false;
try {
start0();
started = true;
} finally {
try {
if (!started) {
group.threadStartFailed(this);
}
} catch (Throwable ignore) {
/* do nothing. If start0 threw a Throwable then
it will be passed up the call stack */
}
}
}
private native void start0();
}
Java程序中的线程不能直接操作硬件,因为它们在虚拟机上运行。start()方法调用本地方法start0(),这是一个用C++实现的与硬件交互的机制。当尝试启动一个已经启动的线程时,会抛出IllegalThreadStateException。线程的启动涉及到线程组的管理,确保线程正确添加并计数。
10万+

被折叠的 条评论
为什么被折叠?



