多线程为什么调用start而不是调用run方法
2017-02-26 11:50
633 查看
run方法只是其中一个方法,
public void run() {
if (target != null) {
target.run();
}
}
而start方法为线程安全,且采用JVI技术实现了多线程
public void run() {
if (target != null) {
target.run();
}
}
而start方法为线程安全,且采用JVI技术实现了多线程
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 */ } } }
相关文章推荐
- 多线程执行时为什么调用的是start()方法而不是run()方法
- 多线程:创建Thread为什么要调用start启动,而不能直接调用run方法
- 为什么我们调用start()方法时会执行run()方法?为什么我们不能直接调用run()方法?他们之间有什么区别?
- 为什么我们调用start()方法时会执行run()方法,为什么我们不能直接调用run()方法?
- 线程为什么调用start()而不是直接调用run()
- 调用线程对象的start()方法会执行run(),为什么不能直接调用run()方法??
- 多线程中调用run()方法和start()方法的简单区别
- 调用start()方法和直接调用run()方法的区别
- 多线程中start和run方法的区别
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- Java传统多线程的实现有两种方法,继承Thread类或者实现Runnable即可.线程启动时调用start()方法.
- 多线程 -- run()方法和start()方法的区别
- java 多线程 - 为什么要覆盖run方法
- Java 入门 之 多线程的 start 和 run 方法
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?
- 为什么java.net.URLEncoder.encode方法要调用两次而不是一次呢?