一个线程总是在没有其他线程的情况下运行

Eug*_*ene 1 java multithreading

为什么主线程永远不会被执行?我认为这是我使用Thread.sleep(int value)我给其他线程运行的机会,但这永远不会发生.

    public static void main(String[] args) {
        final Sook o = new Sook();
        Thread t = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(10000); // Specially set to give a chance to the main thread to run
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        t.run();

        System.out.println("<<<<<BACK TO MAIN >>>>>>"); // Never happens
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*los 12

不要打电话,t.run(),调用t.start()

刚运行会调用当前Thread中的run方法.