• 大王叫我来巡山
    2019-11-06
    配合JVM监控工具VisualVM来学习多线程效果更佳

    作者回复:
    对。Zulu貌似没有这个工具,所以深入学习这些工具之前建议结合自己公司使用的JDK版本。

     1
    
  • Demon.Lee
    2019-09-10
    主线程开始join之前,sleep多长时间合适才能保证子线程已经启动完成了呢,我看老师写的1毫秒,什么依据?

    作者回复:
    下面是Thread里start方法的注释。
    注意到“The result is that two threads are running concurrently”
    所以start方法返回之后,线程是保证已经启动运行了的。

    所以调用start方法,返回之后就可以调用join了。sleep1ms只是一个程序员的多疑。

        /**
         * Causes this thread to begin execution; the Java Virtual Machine
         * calls the <code>run</code> method of this thread.
         * <p>
         * The result is that two threads are running concurrently: the
         * current thread (which returns from the call to the
         * <code>start</code> method) and the other thread (which executes its
         * <code>run</code> method).
         * <p>
         * It is never legal to start a thread more than once.
         * In particular, a thread may not be restarted once it has completed
         * execution.
         *
         * @exception IllegalThreadStateException if the thread was already
         * started.
         * @see #run()
         * @see #stop()
         */
        public synchronized void start() {


     1
    
我们在线,来聊聊吧